class Leafy::FieldValue

Attributes

converter[RW]
id[RW]
name[RW]
raw[RW]
type[RW]

Public Class Methods

new(attributes) click to toggle source
# File lib/leafy/field_value.rb, line 7
def initialize(attributes)
  attributes = attributes.dup.to_a.map { |pair| [pair[0].to_sym, pair[1]]}.to_h

  self.id = attributes.fetch(:id)
  self.name = attributes.fetch(:name)
  self.type = attributes.fetch(:type)
  self.converter = attributes.fetch(:converter) { Leafy.converters.fetch(type.to_sym) { raise(RuntimeError, "unregistered converter #{type}") } }
  self.raw = attributes.fetch(:raw)
end

Public Instance Methods

value() click to toggle source
# File lib/leafy/field_value.rb, line 17
def value
  converter.load(raw)
end
value=(val) click to toggle source
# File lib/leafy/field_value.rb, line 21
def value=(val)
  self.raw = converter.dump(converter.load(val))
end