Class: ToFactory::Generation::Attribute
- Inherits:
-
Object
- Object
- ToFactory::Generation::Attribute
- Defined in:
- lib/to_factory/generation/attribute.rb
Instance Attribute Summary collapse
-
#parser ⇒ Object
writeonly
Sets the attribute parser.
Instance Method Summary collapse
- #format(value, nested = false) ⇒ Object
-
#initialize(attribute, value) ⇒ Attribute
constructor
A new instance of Attribute.
- #inspect_value(value, nested = false) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(attribute, value) ⇒ Attribute
Returns a new instance of Attribute.
6 7 8 9 |
# File 'lib/to_factory/generation/attribute.rb', line 6 def initialize(attribute, value) @attribute = attribute @value = value end |
Instance Attribute Details
#parser=(value) ⇒ Object (writeonly)
Sets the attribute parser
4 5 6 |
# File 'lib/to_factory/generation/attribute.rb', line 4 def parser=(value) @parser = value end |
Instance Method Details
#format(value, nested = false) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/to_factory/generation/attribute.rb', line 26 def format(value, nested=false) case value when Time, DateTime inspect_time(value) when Date value.to_s.inspect when BigDecimal "BigDecimal.new(#{value.to_s.inspect})" when Hash inspect_hash(value, nested) when Array inspect_array(value, nested) when String validate_parseable!(value).inspect else value.inspect end end |
#inspect_value(value, nested = false) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/to_factory/generation/attribute.rb', line 16 def inspect_value(value, nested=false) formatted = format(value, nested) if !value.is_a?(Hash) && !nested formatted = " #{formatted}" end formatted end |
#to_s ⇒ Object
11 12 13 14 |
# File 'lib/to_factory/generation/attribute.rb', line 11 def to_s setter = "#{@attribute}#{inspect_value(@value)}" " #{setter}" end |