1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-27 00:34:41 +01:00
liquid/values/mapslicevalue.go
2017-07-27 18:11:37 -04:00

42 lines
824 B
Go

package values
import (
yaml "gopkg.in/yaml.v2"
)
type mapSliceValue struct {
slice yaml.MapSlice
valueEmbed
}
// func (v mapSliceValue) Equal(o Value) bool { return v.slice == o.Interface() }
func (v mapSliceValue) Interface() interface{} { return v.slice }
func (v mapSliceValue) Contains(elem Value) bool {
e := elem.Interface()
for _, item := range v.slice {
if e == item.Key {
return true
}
}
return false
}
func (v mapSliceValue) IndexValue(index Value) Value {
e := index.Interface()
for _, item := range v.slice {
if e == item.Key {
return ValueOf(item.Value)
}
}
return nilValue
}
func (v mapSliceValue) PropertyValue(index Value) Value {
result := v.IndexValue(index)
if result == nilValue && index.Interface() == sizeKey {
result = ValueOf(len(v.slice))
}
return result
}