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.
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
-
#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 10 |
# 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) @lang = args.fetch(:lang, "ruby") 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 |
#lang ⇒ Object (readonly)
Returns the value of attribute lang.
3 4 5 |
# File 'lib/data_formatter/value.rb', line 3 def lang @lang 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
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/data_formatter/value.rb', line 12 def to_s if is?(Numeric) format_number elsif is?(String) format_string elsif is?(Symbol) format_symbol 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 |