Renamed the Fold* functions to Flatten*
This commit is contained in:
parent
82ef950fd2
commit
ed9c46fc7b
34
activity.go
34
activity.go
|
@ -1765,25 +1765,25 @@ func ToActivity(it Item) (*Activity, error) {
|
|||
return nil, errors.New("unable to convert activity")
|
||||
}
|
||||
|
||||
// FoldIntransitiveActivityProperties
|
||||
func FoldIntransitiveActivityProperties(act IntransitiveActivity) IntransitiveActivity{
|
||||
act.Actor = FoldToIRI(act.Actor)
|
||||
act.Target = FoldToIRI(act.Target)
|
||||
act.Result = FoldToIRI(act.Result)
|
||||
act.Origin = FoldToIRI(act.Origin)
|
||||
act.Result = FoldToIRI(act.Result)
|
||||
act.Instrument = FoldToIRI(act.Instrument)
|
||||
// FlattenIntransitiveActivityProperties flattens the IntransitiveActivity's properties from Object type to IRI
|
||||
func FlattenIntransitiveActivityProperties(act IntransitiveActivity) IntransitiveActivity{
|
||||
act.Actor = FlattenToIRI(act.Actor)
|
||||
act.Target = FlattenToIRI(act.Target)
|
||||
act.Result = FlattenToIRI(act.Result)
|
||||
act.Origin = FlattenToIRI(act.Origin)
|
||||
act.Result = FlattenToIRI(act.Result)
|
||||
act.Instrument = FlattenToIRI(act.Instrument)
|
||||
return act
|
||||
}
|
||||
|
||||
// FoldActivityProperties
|
||||
func FoldActivityProperties(act Activity) Activity {
|
||||
act.Object = FoldToIRI(act.Object)
|
||||
act.Actor = FoldToIRI(act.Actor)
|
||||
act.Target = FoldToIRI(act.Target)
|
||||
act.Result = FoldToIRI(act.Result)
|
||||
act.Origin = FoldToIRI(act.Origin)
|
||||
act.Result = FoldToIRI(act.Result)
|
||||
act.Instrument = FoldToIRI(act.Instrument)
|
||||
// FlattenActivityProperties flattens the Activity's properties from Object type to IRI
|
||||
func FlattenActivityProperties(act Activity) Activity {
|
||||
act.Object = FlattenToIRI(act.Object)
|
||||
act.Actor = FlattenToIRI(act.Actor)
|
||||
act.Target = FlattenToIRI(act.Target)
|
||||
act.Result = FlattenToIRI(act.Result)
|
||||
act.Origin = FlattenToIRI(act.Origin)
|
||||
act.Result = FlattenToIRI(act.Result)
|
||||
act.Instrument = FlattenToIRI(act.Instrument)
|
||||
return act
|
||||
}
|
||||
|
|
|
@ -2357,10 +2357,10 @@ func TestToActivity(t *testing.T) {
|
|||
t.Skipf("TODO")
|
||||
}
|
||||
|
||||
func TestFoldActivityProperties(t *testing.T) {
|
||||
func TestFlattenActivityProperties(t *testing.T) {
|
||||
t.Skipf("TODO")
|
||||
}
|
||||
|
||||
func TestFoldIntransitiveActivityProperties(t *testing.T) {
|
||||
func TestFlattenIntransitiveActivityProperties(t *testing.T) {
|
||||
t.Skipf("TODO")
|
||||
}
|
||||
|
|
|
@ -294,11 +294,11 @@ func (o *OrderedCollectionPage) Collection() CollectionInterface {
|
|||
return o
|
||||
}
|
||||
|
||||
// FoldItemCollection
|
||||
func FoldItemCollection(c ItemCollection) ItemCollection {
|
||||
// FlattenItemCollection flattens the Collection's properties from Object type to IRI
|
||||
func FlattenItemCollection(c ItemCollection) ItemCollection {
|
||||
if c != nil && len(c) > 0 {
|
||||
for i, it := range c {
|
||||
c[i] = FoldToIRI(it)
|
||||
c[i] = FlattenToIRI(it)
|
||||
}
|
||||
}
|
||||
return c
|
||||
|
|
|
@ -494,6 +494,6 @@ func TestOrderedCollectionPage_Collection(t *testing.T) {
|
|||
t.Skipf("TODO")
|
||||
}
|
||||
|
||||
func TestFoldItemCollection(t *testing.T) {
|
||||
func TestFlattenItemCollection(t *testing.T) {
|
||||
t.Skipf("TODO")
|
||||
}
|
||||
|
|
4
iri.go
4
iri.go
|
@ -46,8 +46,8 @@ func (i IRI) IsObject() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// FoldToIRI
|
||||
func FoldToIRI(it Item) Item {
|
||||
// FlattenToIRI checks if Item can be flatten to an IRI and returns it if so
|
||||
func FlattenToIRI(it Item) Item {
|
||||
if it!= nil && it.IsObject() && len(it.GetLink()) > 0 {
|
||||
return it.GetLink()
|
||||
}
|
||||
|
|
|
@ -59,6 +59,6 @@ func TestIRI_UnmarshalJSON(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFoldToIRI(t *testing.T) {
|
||||
func TestFlattenToIRI(t *testing.T) {
|
||||
t.Skipf("TODO")
|
||||
}
|
||||
|
|
28
object.go
28
object.go
|
@ -630,8 +630,8 @@ func ToObject(it Item) (*Object, error) {
|
|||
return nil, errors.New("unable to convert object")
|
||||
}
|
||||
|
||||
// FoldObjectProperties
|
||||
func FoldObjectProperties(o Object) Object {
|
||||
// FlattenObjectProperties flattens the Object's properties from Object types to IRI
|
||||
func FlattenObjectProperties(o Object) Object {
|
||||
if o.Replies != nil && o.Replies.IsObject() {
|
||||
if len(o.Replies.GetLink()) > 0 {
|
||||
o.Replies = o.Replies.GetLink()
|
||||
|
@ -639,32 +639,32 @@ func FoldObjectProperties(o Object) Object {
|
|||
o.Replies = IRI(fmt.Sprintf("%s/replies", o.GetLink()))
|
||||
}
|
||||
}
|
||||
o.AttributedTo = FoldToIRI(o.AttributedTo)
|
||||
o.InReplyTo = FoldToIRI(o.InReplyTo)
|
||||
o.AttributedTo = FlattenToIRI(o.AttributedTo)
|
||||
o.InReplyTo = FlattenToIRI(o.InReplyTo)
|
||||
|
||||
o.To = FoldItemCollection(o.To)
|
||||
o.Bto = FoldItemCollection(o.Bto)
|
||||
o.CC = FoldItemCollection(o.CC)
|
||||
o.BCC = FoldItemCollection(o.BCC)
|
||||
o.Audience = FoldItemCollection(o.Audience)
|
||||
o.To = FlattenItemCollection(o.To)
|
||||
o.Bto = FlattenItemCollection(o.Bto)
|
||||
o.CC = FlattenItemCollection(o.CC)
|
||||
o.BCC = FlattenItemCollection(o.BCC)
|
||||
o.Audience = FlattenItemCollection(o.Audience)
|
||||
|
||||
o.Tag = FoldItemCollection(o.Tag)
|
||||
o.Tag = FlattenItemCollection(o.Tag)
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
// FoldProperties
|
||||
func FoldProperties(it Item) Item {
|
||||
// FlattenProperties flattens the Item's properties from Object types to IRI
|
||||
func FlattenProperties(it Item) Item {
|
||||
if ValidActivityType(it.GetType()) {
|
||||
act, err := ToActivity(it)
|
||||
if err == nil {
|
||||
return FoldActivityProperties(*act)
|
||||
return FlattenActivityProperties(*act)
|
||||
}
|
||||
}
|
||||
if ValidActorType(it.GetType()) || ValidObjectType(it.GetType()) {
|
||||
ob, err := ToObject(it)
|
||||
if err == nil {
|
||||
return FoldObjectProperties(*ob)
|
||||
return FlattenObjectProperties(*ob)
|
||||
}
|
||||
}
|
||||
return it
|
||||
|
|
|
@ -509,10 +509,10 @@ func TestToObject(t *testing.T) {
|
|||
t.Skipf("TODO")
|
||||
}
|
||||
|
||||
func TestFoldObjectProperties(t *testing.T) {
|
||||
func TestFlattenObjectProperties(t *testing.T) {
|
||||
t.Skipf("TODO")
|
||||
}
|
||||
|
||||
func TestFoldProperties(t *testing.T) {
|
||||
func TestFlattenProperties(t *testing.T) {
|
||||
t.Skipf("TODO")
|
||||
}
|
||||
|
|
Reference in a new issue