Class: BinaryCodec::Issue
Instance Attribute Summary
#bytes
Class Method Summary
collapse
Instance Method Summary
collapse
from_bytes, from_hex, from_json, get_type_by_name, #to_byte_sink, #to_bytes, #to_hex, #value_of
Constructor Details
#initialize(bytes = nil) ⇒ Issue
Returns a new instance of Issue.
5
6
7
|
# File 'lib/binary-codec/types/issue.rb', line 5
def initialize(bytes = nil)
super(bytes || [])
end
|
Class Method Details
.from(value) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/binary-codec/types/issue.rb', line 9
def self.from(value)
return value if value.is_a?(Issue)
if value.is_a?(String)
return Issue.new(hex_to_bytes(value))
end
if value.is_a?(Hash) || value.is_a?(::Hash)
bytes = []
bytes.concat(Currency.from(value['currency']).to_bytes)
bytes.concat(AccountId.from(value['issuer']).to_bytes) if value['issuer']
return Issue.new(bytes)
end
raise StandardError, "Cannot construct Issue from #{value.class}"
end
|
.from_parser(parser, _hint = nil) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/binary-codec/types/issue.rb', line 26
def self.from_parser(parser, _hint = nil)
bytes = []
bytes.concat(parser.read(20))
bytes.concat(parser.read(20)) unless parser.end?
Issue.new(bytes)
end
|
Instance Method Details
#to_json(_definitions = nil, _field_name = nil) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/binary-codec/types/issue.rb', line 42
def to_json(_definitions = nil, _field_name = nil)
parser = BinaryParser.new(to_hex)
result = {}
result['currency'] = Currency.from_parser(parser).to_json
result['issuer'] = AccountId.from_parser(parser).to_json unless parser.end?
result
end
|