Class: CompactData::Model::CompactDataPair
- Inherits:
-
Object
- Object
- CompactData::Model::CompactDataPair
- Defined in:
- lib/compactdata/model/model.rb
Overview
A CompactData PAir
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(key, value) ⇒ CompactDataPair
constructor
A new instance of CompactDataPair.
- #to_j ⇒ Object
- #to_m ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(key, value) ⇒ CompactDataPair
Returns a new instance of CompactDataPair.
103 104 105 106 |
# File 'lib/compactdata/model/model.rb', line 103 def initialize(key, value) @key = key @value = value end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
101 102 103 |
# File 'lib/compactdata/model/model.rb', line 101 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
101 102 103 |
# File 'lib/compactdata/model/model.rb', line 101 def value @value end |
Instance Method Details
#to_j ⇒ Object
112 113 114 |
# File 'lib/compactdata/model/model.rb', line 112 def to_j { @key => @value.to_j } end |
#to_m ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/compactdata/model/model.rb', line 116 def to_m key = UTIL.non_string_primitive?(@key) ? "\"#{@key}\"" : @key if @value.instance_of?(CompactDataPair) "#{key}(#{@value.to_m})" elsif @value.instance_of?(CompactDataMap) || @value.instance_of?(CompactDataArray) "#{key}#{@value.to_m}" else "#{key}=#{@value.to_m}" end end |
#to_s ⇒ Object
108 109 110 |
# File 'lib/compactdata/model/model.rb', line 108 def to_s "CompactDataPair: #{key}=#{@value}" end |