Class: DataFormatter::ValuePair

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

Constant Summary collapse

Separators =
{
  "ruby" => "=>",
  "js" => ":"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ ValuePair

Returns a new instance of ValuePair.



11
12
13
14
15
16
# File 'lib/data_formatter/value_pair.rb', line 11

def initialize(args)
  @key = args.fetch(:key)
  @value = args.fetch(:value)
  @lang = args.fetch(:lang, "ruby")
  @separator = Separators[@lang]
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/data_formatter/value_pair.rb', line 4

def key
  @key
end

#langObject (readonly)

Returns the value of attribute lang.



4
5
6
# File 'lib/data_formatter/value_pair.rb', line 4

def lang
  @lang
end

#separatorObject (readonly)

Returns the value of attribute separator.



4
5
6
# File 'lib/data_formatter/value_pair.rb', line 4

def separator
  @separator
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/data_formatter/value_pair.rb', line 4

def value
  @value
end

Instance Method Details

#to_sObject



18
19
20
# File 'lib/data_formatter/value_pair.rb', line 18

def to_s
  [key.to_s, %Q{<span class="hashrocket">&nbsp;#{separator}&nbsp;</span>}, value.to_s].join
end