Class: DataFormatter::ValuePair
- Inherits:
-
Object
- Object
- DataFormatter::ValuePair
- Defined in:
- lib/data_formatter/value_pair.rb
Constant Summary collapse
- Separators =
{ "ruby" => "=>", "js" => ":" }
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(args) ⇒ ValuePair
constructor
A new instance of ValuePair.
- #to_s ⇒ Object
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
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/data_formatter/value_pair.rb', line 4 def key @key end |
#lang ⇒ Object (readonly)
Returns the value of attribute lang.
4 5 6 |
# File 'lib/data_formatter/value_pair.rb', line 4 def lang @lang end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
4 5 6 |
# File 'lib/data_formatter/value_pair.rb', line 4 def separator @separator end |
#value ⇒ Object (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_s ⇒ Object
18 19 20 |
# File 'lib/data_formatter/value_pair.rb', line 18 def to_s [key.to_s, %Q{<span class="hashrocket"> #{separator} </span>}, value.to_s].join end |