Class: DataFormatter::Value
- Inherits:
-
Object
- Object
- DataFormatter::Value
- Defined in:
- lib/data_formatter/value.rb
Instance Attribute Summary collapse
-
#indentation ⇒ Object
readonly
Returns the value of attribute indentation.
-
#is_key ⇒ Object
readonly
Returns the value of attribute is_key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(args) ⇒ Value
constructor
A new instance of Value.
- #to_s ⇒ Object
Constructor Details
#initialize(args) ⇒ Value
Returns a new instance of Value.
5 6 7 8 9 |
# File 'lib/data_formatter/value.rb', line 5 def initialize(args) @value = args.fetch(:data) @is_key = args.fetch(:is_key, false) @indentation = args.fetch(:indentation) end |
Instance Attribute Details
#indentation ⇒ Object (readonly)
Returns the value of attribute indentation.
3 4 5 |
# File 'lib/data_formatter/value.rb', line 3 def indentation @indentation end |
#is_key ⇒ Object (readonly)
Returns the value of attribute is_key.
3 4 5 |
# File 'lib/data_formatter/value.rb', line 3 def is_key @is_key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/data_formatter/value.rb', line 3 def value @value end |
Instance Method Details
#to_s ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/data_formatter/value.rb', line 11 def to_s if is?(Numeric) format_number elsif is?(String) format_string elsif is?(TrueClass, FalseClass) format_boolean elsif is?(NilClass) format_nil elsif is?(Hash) format_hash elsif is?(Array) format_array else raise "ValueFormatter value is of unsupported type: #{ value.class.name }" end.to_s end |