Class: ToFactory::Generation::Attribute
- Inherits:
-
Object
- Object
- ToFactory::Generation::Attribute
- Defined in:
- lib/to_factory/generation/attribute.rb
Instance Method Summary collapse
- #format(value, nested) ⇒ 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.
4 5 6 7 |
# File 'lib/to_factory/generation/attribute.rb', line 4 def initialize(attribute, value) @attribute = attribute @value = value end |
Instance Method Details
#format(value, nested) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/to_factory/generation/attribute.rb', line 29 def format(value, nested) case value when Time, DateTime inspect_time(value) when BigDecimal value.to_f.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
19 20 21 22 23 24 25 26 27 |
# File 'lib/to_factory/generation/attribute.rb', line 19 def inspect_value(value, nested=false) formatted = format(value, nested) if !value.is_a?(Hash) && !nested formatted = " #{formatted}" end formatted end |
#to_s ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/to_factory/generation/attribute.rb', line 9 def to_s setter = "#{@attribute}#{inspect_value(@value)}" if ToFactory.new_syntax? " #{setter}" else " o.#{setter}" end end |