Class: DataFormatter::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/data_formatter/value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#indentationObject (readonly)

Returns the value of attribute indentation.



3
4
5
# File 'lib/data_formatter/value.rb', line 3

def indentation
  @indentation
end

#is_keyObject (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

#langObject (readonly)

Returns the value of attribute lang.



3
4
5
# File 'lib/data_formatter/value.rb', line 3

def lang
  @lang
end

#valueObject (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_sObject



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