Class: BoaVista::Line
- Inherits:
-
Object
- Object
- BoaVista::Line
- Defined in:
- lib/boa_vista/line.rb
Instance Attribute Summary collapse
-
#layout ⇒ Object
Returns the value of attribute layout.
Class Method Summary collapse
Instance Method Summary collapse
- #create_method_to_field(name) ⇒ Object
- #parse ⇒ Object
- #read ⇒ Object
- #to_hash ⇒ Object
- #write ⇒ Object
Instance Attribute Details
#layout ⇒ Object
Returns the value of attribute layout.
3 4 5 |
# File 'lib/boa_vista/line.rb', line 3 def layout @layout end |
Class Method Details
.prepare_for_read(value, layout) ⇒ Object
5 6 7 |
# File 'lib/boa_vista/line.rb', line 5 def self.prepare_for_read(value, layout) new(value, layout) end |
.prepare_for_write(attributes, layout) ⇒ Object
9 10 11 |
# File 'lib/boa_vista/line.rb', line 9 def self.prepare_for_write(attributes, layout) new(nil, layout, attributes) end |
Instance Method Details
#create_method_to_field(name) ⇒ Object
48 49 50 |
# File 'lib/boa_vista/line.rb', line 48 def create_method_to_field(name) define_singleton_method(name) { @fields[name].value } end |
#parse ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/boa_vista/line.rb', line 32 def parse @layout.attributes.each do |field, | value_for_option = { value: @attributes[field] } @fields = @fields.merge(field => BoaVista::Field::Writer.new(field, .merge(value_for_option))) create_method_to_field(field) end self end |
#read ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/boa_vista/line.rb', line 13 def read @layout.attributes.each do |field, | value = { value: @value } @fields = @fields.merge(field => BoaVista::Field::Reader.new(field, .merge(value)).call) create_method_to_field(field) end self end |
#to_hash ⇒ Object
44 45 46 |
# File 'lib/boa_vista/line.rb', line 44 def to_hash Hash[@fields.map { |k, v| [v.name, v.value]}] end |
#write ⇒ Object
25 26 27 28 29 30 |
# File 'lib/boa_vista/line.rb', line 25 def write parse @value = @layout.attributes.keys.inject('') do |line, attribute| line << @fields.fetch(attribute).call end end |