Class: Calldata::Msg

Inherits:
Calldata show all
Defined in:
lib/calldata/parser.rb

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

#dataObject (readonly)

Returns the value of attribute data.



95
96
97
# File 'lib/calldata/parser.rb', line 95

def data
  @data
end

#typeObject (readonly)

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

Returns:

  • (Boolean)


82
83
84
85
86
87
88
# File 'lib/calldata/parser.rb', line 82

def self.valid?( text )
   ## quick check for now
   ##  stripped text MUST start with { and  end with }
   ##  for auto-detect 
   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?

Returns:

  • (Boolean)


103
# File 'lib/calldata/parser.rb', line 103

def key?( key ) @data.key?( key); end

#keysObject



105
# File 'lib/calldata/parser.rb', line 105

def keys() @data.keys; end

#to_hObject



108
# File 'lib/calldata/parser.rb', line 108

def to_h() @data; end

#valuesObject



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