Class: Calldata::Msg
Constant Summary
Constants inherited
from Calldata
MAJOR, MINOR, PATCH, VERSION
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Calldata
banner, decode, encode, parse_data, parse_hex, root, valid_data?, valid_hex?, version
Constructor Details
#initialize(data) ⇒ Msg
Returns a new instance of Msg.
96
97
98
99
|
# File 'lib/calldata/parser.rb', line 96
def initialize( data )
@data = data
@type = 'application/json'
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
95
96
97
|
# File 'lib/calldata/parser.rb', line 95
def data
@data
end
|
#type ⇒ Object
Returns the value of attribute type.
95
96
97
|
# File 'lib/calldata/parser.rb', line 95
def type
@type
end
|
Class Method Details
.parse(text) ⇒ Object
90
91
92
93
|
# File 'lib/calldata/parser.rb', line 90
def self.parse( text )
data = JSON.parse( text )
new( data )
end
|
.valid?(text) ⇒ Boolean
82
83
84
85
86
87
88
|
# File 'lib/calldata/parser.rb', line 82
def self.valid?( text )
text = text.strip
text.start_with?( '{') && text.end_with?( '}' )
end
|
Instance Method Details
#[](key) ⇒ Object
add direct hash-like methods - why? why not?
102
|
# File 'lib/calldata/parser.rb', line 102
def [](key) @data[key]; end
|
#key?(key) ⇒ Boolean
Also known as:
has_key?
103
|
# File 'lib/calldata/parser.rb', line 103
def key?( key ) @data.key?( key); end
|
#keys ⇒ Object
105
|
# File 'lib/calldata/parser.rb', line 105
def keys() @data.keys; end
|
#to_h ⇒ Object
108
|
# File 'lib/calldata/parser.rb', line 108
def to_h() @data; end
|
#values ⇒ Object
106
|
# File 'lib/calldata/parser.rb', line 106
def values() @data.values; end
|
#write(path) ⇒ Object
110
|
# File 'lib/calldata/parser.rb', line 110
def write( path ) write_json( path, @data ); end
|