nem-ruby 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/examples/apostille_audit.rb +1 -1
- data/examples/apostille_create.rb +1 -1
- data/examples/endpoint/account.rb +2 -2
- data/examples/endpoint/account_local.rb +1 -1
- data/examples/endpoint/block.rb +2 -1
- data/examples/endpoint/chain.rb +1 -1
- data/examples/endpoint/debug.rb +1 -1
- data/examples/endpoint/mosaic.rb +1 -1
- data/examples/endpoint/namespace.rb +1 -1
- data/examples/endpoint/node.rb +1 -1
- data/examples/endpoint/timesync.rb +1 -1
- data/examples/endpoint/transaction.rb +1 -1
- data/examples/nis.rb +1 -1
- data/examples/node_pool.rb +3 -3
- data/examples/offline/announce_offline_transfer.rb +1 -1
- data/examples/transaction/importance_transfer.rb +1 -1
- data/examples/transaction/mosaic_definition_creation.rb +1 -1
- data/examples/transaction/mosaic_supply_change.rb +1 -1
- data/examples/transaction/multisig_add_cosignatory.rb +1 -1
- data/examples/transaction/multisig_aggregate_modification.rb +1 -3
- data/examples/transaction/multisig_signature.rb +1 -1
- data/examples/transaction/provision_namespace.rb +1 -1
- data/examples/transaction/transfer.rb +1 -1
- data/examples/transaction/transfer_mosaic.rb +1 -1
- data/examples/transaction/transfer_with_encrypted_message.rb +1 -1
- data/lib/nem/client.rb +1 -1
- data/lib/nem/configuration.rb +2 -3
- data/lib/nem/mixin/assignable.rb +3 -0
- data/lib/nem/model/nis_node_info.rb +11 -1
- data/lib/nem/model/node.rb +25 -3
- data/lib/nem/model/transfer_transaction.rb +1 -1
- data/lib/nem/request/announce.rb +3 -0
- data/lib/nem/util.rb +0 -8
- data/lib/nem/version.rb +1 -1
- metadata +3 -4
- data/lib/nem/util/assignable.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 748ca73f087e9f567496b5c698b6d1b81bbbd192601e8bbdb17efdb202eede92
|
4
|
+
data.tar.gz: 2e9f12cc146d126bcd67b37b68dacaac5c62fbc02e36923ce3e1fdbffd73831f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b7d3becf508d3eff05b8031b443bfc36673a703cc68cd867f0c18c891802e1a2e9d02677875122ddb595c822e75db63691c9f0a2b1938cc1f1ca62f15bd0240
|
7
|
+
data.tar.gz: a0e386cd6014fc1e6f24908bd6129cc8f44c1789e098a076153f26ba85cde49f8dc485fd1f5ffa3bfca4642c48194ab8e5d0516d6552268fbd484979484f3a85
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# nem-ruby
|
2
2
|
|
3
|
-
[](https://travis-ci.org/44uk/nem-ruby)
|
4
3
|
[](https://badge.fury.io/rb/nem-ruby)
|
4
|
+
[](https://travis-ci.org/44uk/nem-ruby)
|
5
5
|
[](https://codeclimate.com/github/44uk/nem-ruby)
|
6
6
|
[](https://gitter.im/44uk/nem-ruby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
7
7
|
|
data/examples/apostille_audit.rb
CHANGED
@@ -5,7 +5,7 @@ Nem.logger.level = Logger::DEBUG
|
|
5
5
|
|
6
6
|
FIXTURES_PATH = File.expand_path('../../spec/fixtures', __FILE__)
|
7
7
|
|
8
|
-
node = Nem::Node.new(host: '
|
8
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
9
9
|
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
10
10
|
|
11
11
|
# transaction hash from Filename
|
@@ -9,7 +9,7 @@ FIXTURES_PATH = File.expand_path('../../spec/fixtures', __FILE__)
|
|
9
9
|
A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
10
10
|
|
11
11
|
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
12
|
-
node = Nem::Node.new(host: '
|
12
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
13
13
|
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
14
14
|
|
15
15
|
file = File.open("#{FIXTURES_PATH}/nemLogoV2.png")
|
@@ -4,13 +4,13 @@ require 'nem'
|
|
4
4
|
Nem.logger.level = Logger::DEBUG
|
5
5
|
|
6
6
|
# single node
|
7
|
-
# node = Nem::Node.new(host: '
|
7
|
+
# node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
8
8
|
|
9
9
|
# multiple nodes
|
10
10
|
node = Nem::NodePool.new([
|
11
11
|
Nem::Node.new(host: 'bigalice2.nem.ninja'),
|
12
12
|
Nem::Node.new(host: '192.3.61.243'),
|
13
|
-
Nem::Node.new(host: '
|
13
|
+
Nem::Node.new(host: 'bigalice2.nem.ninja')
|
14
14
|
])
|
15
15
|
|
16
16
|
# new Account Endpoint Object
|
data/examples/endpoint/block.rb
CHANGED
@@ -2,8 +2,9 @@ require 'pp'
|
|
2
2
|
require 'nem'
|
3
3
|
|
4
4
|
Nem.logger.level = Logger::DEBUG
|
5
|
+
Nem.debug = true
|
5
6
|
|
6
|
-
node = Nem::Node.new(host: '
|
7
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
7
8
|
|
8
9
|
# new Block Endpoint Object
|
9
10
|
block_endpoint = Nem::Endpoint::Block.new(node)
|
data/examples/endpoint/chain.rb
CHANGED
data/examples/endpoint/debug.rb
CHANGED
data/examples/endpoint/mosaic.rb
CHANGED
data/examples/endpoint/node.rb
CHANGED
data/examples/nis.rb
CHANGED
data/examples/node_pool.rb
CHANGED
@@ -7,17 +7,17 @@ Nem.logger.level = Logger::DEBUG
|
|
7
7
|
nodes = Nem::NodePool.new([
|
8
8
|
Nem::Node.new(host: 'dummy1.example.com'),
|
9
9
|
Nem::Node.new(host: 'dummy2.example.com'),
|
10
|
-
Nem::Node.new(host: '
|
10
|
+
Nem::Node.new(host: 'bigalice2.nem.ninja')
|
11
11
|
])
|
12
12
|
|
13
13
|
# Create from hash definitions
|
14
14
|
# nodes = Nem::NodePool.from_hash([
|
15
15
|
# {host: 'dummy1.example.com'},
|
16
16
|
# {host: 'dummy2.example.com'},
|
17
|
-
# {host: '
|
17
|
+
# {host: 'bigalice2.nem.ninja'}
|
18
18
|
# ])
|
19
19
|
|
20
20
|
account_endpoint = Nem::Endpoint::Account.new(nodes)
|
21
21
|
|
22
|
-
# switch to
|
22
|
+
# switch to bigalice2.nem.ninja
|
23
23
|
pp account_endpoint.find('TBULEAUG2CZQISUR442HWA6UAKGWIXHDABJVIPS4')
|
@@ -10,7 +10,7 @@ A_PRIVATE_KEY = '260206d683962350532408e8774fd14870a173b7fba17f6b504da3dbc5f1cc9
|
|
10
10
|
B_PUBLIC_KEY = 'cc6c9485d15b992501e57fe3799487e99de272f79c5442de94eeb998b45e0144'
|
11
11
|
|
12
12
|
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
13
|
-
node = Nem::Node.new(host: '
|
13
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
14
14
|
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
15
15
|
|
16
16
|
tx = Nem::Transaction::ImportanceTransfer.new(B_PUBLIC_KEY, :activate)
|
@@ -39,7 +39,7 @@ definition = Nem::Model::MosaicDefinition.new(
|
|
39
39
|
)
|
40
40
|
|
41
41
|
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
42
|
-
node = Nem::Node.new(host: '
|
42
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
43
43
|
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
44
44
|
|
45
45
|
tx = Nem::Transaction::MosaicDefinitionCreation.new(definition)
|
@@ -12,7 +12,7 @@ mosaic_id = Nem::Model::MosaicId.new(
|
|
12
12
|
)
|
13
13
|
|
14
14
|
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
15
|
-
node = Nem::Node.new(host: '
|
15
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
16
16
|
|
17
17
|
tx = Nem::Transaction::MosaicSupplyChange.new(mosaic_id, :increase, 1_000)
|
18
18
|
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
@@ -13,7 +13,7 @@ A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b83421
|
|
13
13
|
B_PUBLIC_KEY = '9e7ab2924cd1a3482df784db190614cfc8a33671f5d80a5b15a9c9e8b4d13933'
|
14
14
|
|
15
15
|
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
16
|
-
node = Nem::Node.new(host: '
|
16
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
17
17
|
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
18
18
|
|
19
19
|
msig_cosigratories = [
|
@@ -7,12 +7,10 @@ Nem.logger.level = Logger::DEBUG
|
|
7
7
|
M_PRIVATE_KEY = '00f077782658ae91b77f238ba5fcd7ef110564b5c189072e4d4590d9b17f9d76f3'
|
8
8
|
|
9
9
|
# cosignatory(A)
|
10
|
-
# A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
11
10
|
A_PUBLIC_KEY = 'be2ba9cb15a547110d511a4d43c0482fbb584d78781abac01fb053d18f4a0033'
|
12
11
|
|
13
12
|
kp = Nem::Keypair.new(M_PRIVATE_KEY)
|
14
|
-
node = Nem::Node.new(host: '
|
15
|
-
node = Nem::Node.new
|
13
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
16
14
|
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
17
15
|
|
18
16
|
msig_cosignatories = [
|
@@ -18,7 +18,7 @@ B_PUBLIC_KEY = '9e7ab2924cd1a3482df784db190614cfc8a33671f5d80a5b15a9c9e8b4d13933
|
|
18
18
|
B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
|
19
19
|
|
20
20
|
kp = Nem::Keypair.new(B_PRIVATE_KEY)
|
21
|
-
node = Nem::Node.new(host: '
|
21
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
22
22
|
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
23
23
|
account_endpoint = Nem::Endpoint::Account.new(node)
|
24
24
|
|
@@ -7,7 +7,7 @@ Nem.logger.level = Logger::DEBUG
|
|
7
7
|
A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
8
8
|
|
9
9
|
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
10
|
-
node = Nem::Node.new(host: '
|
10
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
11
11
|
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
12
12
|
|
13
13
|
tx = Nem::Transaction::ProvisionNamespace.new('sushi')
|
@@ -18,7 +18,7 @@ A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b83421
|
|
18
18
|
B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
|
19
19
|
|
20
20
|
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
21
|
-
node = Nem::Node.new(host: '
|
21
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
22
22
|
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
23
23
|
|
24
24
|
# with plain message
|
@@ -10,7 +10,7 @@ A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b83421
|
|
10
10
|
B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
|
11
11
|
|
12
12
|
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
13
|
-
node = Nem::Node.new(host: '
|
13
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
14
14
|
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
15
15
|
# ns_endpoint = Nem::Endpoint::Namespace.new(node)
|
16
16
|
|
@@ -19,7 +19,7 @@ B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
|
|
19
19
|
B_PUBLIC_KEY = '9e7ab2924cd1a3482df784db190614cfc8a33671f5d80a5b15a9c9e8b4d13933'
|
20
20
|
|
21
21
|
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
22
|
-
node = Nem::Node.new(host: '
|
22
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
23
23
|
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
24
24
|
|
25
25
|
# with encrypted message
|
data/lib/nem/client.rb
CHANGED
@@ -41,7 +41,7 @@ class Nem::Client
|
|
41
41
|
# @param [Hash] params API Parameters
|
42
42
|
# @return [Hash] Hash converted API Response
|
43
43
|
def request(method, path, params = {})
|
44
|
-
log(method, path, params)
|
44
|
+
log(method, path, params) if Nem.debug
|
45
45
|
if connection.remote? && local_only?(path)
|
46
46
|
raise Nem::Error, "The request (#{method} #{path}) is only permitted to local NIS."
|
47
47
|
end
|
data/lib/nem/configuration.rb
CHANGED
@@ -4,14 +4,13 @@ module Nem
|
|
4
4
|
module Configuration
|
5
5
|
DEADLINE = 3600
|
6
6
|
|
7
|
-
|
8
|
-
# @return [Logger]
|
9
|
-
attr_accessor :logger, :deadline, :default_network
|
7
|
+
attr_accessor :logger, :deadline, :default_network, :debug
|
10
8
|
|
11
9
|
def self.extended(base)
|
12
10
|
base.logger = Logger.new($stdout).tap { |l| l.level = Logger::INFO }
|
13
11
|
base.deadline = DEADLINE
|
14
12
|
base.default_network = :testnet
|
13
|
+
base.debug = false
|
15
14
|
end
|
16
15
|
|
17
16
|
# @yield [self]
|
data/lib/nem/mixin/assignable.rb
CHANGED
@@ -4,6 +4,9 @@ module Nem
|
|
4
4
|
def initialize(attributes = {})
|
5
5
|
attributes.each do |k, v|
|
6
6
|
instance_variable_set("@#{k.to_s}", v) if respond_to?("#{k.to_s}")
|
7
|
+
if !respond_to?("#{k.to_s}")
|
8
|
+
Nem.logger.warn "Detected unknown key-value. #{k} => #{v} while assigning #{self.class.name}"
|
9
|
+
end
|
7
10
|
end if attributes
|
8
11
|
yield self if block_given?
|
9
12
|
end
|
@@ -8,6 +8,16 @@ module Nem
|
|
8
8
|
:start_time,
|
9
9
|
:version,
|
10
10
|
:signer
|
11
|
+
|
12
|
+
def self.new_from_nis_info(hash)
|
13
|
+
new(
|
14
|
+
current_time: hash[:currentTime],
|
15
|
+
application: hash[:application],
|
16
|
+
start_time: hash[:startTime],
|
17
|
+
version: hash[:version],
|
18
|
+
signer: hash[:signer]
|
19
|
+
)
|
20
|
+
end
|
11
21
|
end
|
12
22
|
|
13
23
|
class NisNodeInfo
|
@@ -18,7 +28,7 @@ module Nem
|
|
18
28
|
def self.new_from_nis_node_info(hash)
|
19
29
|
new(
|
20
30
|
node: Node.new_from_node(hash[:node]),
|
21
|
-
nis_info: NisInfo.
|
31
|
+
nis_info: NisInfo.new_from_nis_info(hash[:nisInfo])
|
22
32
|
)
|
23
33
|
end
|
24
34
|
end
|
data/lib/nem/model/node.rb
CHANGED
@@ -6,20 +6,42 @@ module Nem
|
|
6
6
|
attr_reader :features,
|
7
7
|
:network,
|
8
8
|
:application,
|
9
|
+
:network_id,
|
9
10
|
:version,
|
10
11
|
:platform
|
12
|
+
|
13
|
+
def self.new_from_metadata(hash)
|
14
|
+
new(
|
15
|
+
features: hash[:features],
|
16
|
+
application: hash[:application],
|
17
|
+
network_id: hash[:networkId],
|
18
|
+
version: hash[:version],
|
19
|
+
platform: hash[:platform]
|
20
|
+
)
|
21
|
+
end
|
11
22
|
end
|
12
23
|
|
13
24
|
class NodeEndpoint
|
14
25
|
include Nem::Mixin::Assignable
|
15
26
|
|
16
27
|
attr_reader :protocol, :port, :host
|
28
|
+
|
29
|
+
def self.new_from_endpoint(hash)
|
30
|
+
new(hash)
|
31
|
+
end
|
17
32
|
end
|
18
33
|
|
19
34
|
class NodeIdentity
|
20
35
|
include Nem::Mixin::Assignable
|
21
36
|
|
22
37
|
attr_reader :name, :public_key
|
38
|
+
|
39
|
+
def self.new_from_identity(hash)
|
40
|
+
new(
|
41
|
+
name: hash[:name],
|
42
|
+
public_key: hash[:"public-key"]
|
43
|
+
)
|
44
|
+
end
|
23
45
|
end
|
24
46
|
|
25
47
|
class Node
|
@@ -31,9 +53,9 @@ module Nem
|
|
31
53
|
|
32
54
|
def self.new_from_node(hash)
|
33
55
|
new(
|
34
|
-
metadata: NodeMetadata.
|
35
|
-
endpoint: NodeEndpoint.
|
36
|
-
identity: NodeIdentity.
|
56
|
+
metadata: NodeMetadata.new_from_metadata(hash[:metaData]),
|
57
|
+
endpoint: NodeEndpoint.new_from_endpoint(hash[:endpoint]),
|
58
|
+
identity: NodeIdentity.new_from_identity(hash[:identity])
|
37
59
|
)
|
38
60
|
end
|
39
61
|
end
|
data/lib/nem/request/announce.rb
CHANGED
@@ -17,6 +17,9 @@ module Nem
|
|
17
17
|
# @return [Hash] Attribute and value pairs
|
18
18
|
def to_entity(state = nil)
|
19
19
|
entity = prepare_entity
|
20
|
+
if Nem.debug
|
21
|
+
Nem.logger.debug '%s' % [entity.inspect]
|
22
|
+
end
|
20
23
|
if state == :prepare
|
21
24
|
{ transaction: entity,
|
22
25
|
privateKey: keypair.private }
|
data/lib/nem/util.rb
CHANGED
@@ -6,14 +6,6 @@ module Nem::Util
|
|
6
6
|
MAINNET = 0x68000000 # 1744830464
|
7
7
|
MIJIN = 0x60000000
|
8
8
|
|
9
|
-
VERSION_1 = 0x00000001 # 1
|
10
|
-
VERSION_2 = 0x00000002 # 2
|
11
|
-
|
12
|
-
TESTNET_VERSION_1 = TESTNET | VERSION_1 # 0x98000001 = -1744830463
|
13
|
-
TESTNET_VERSION_2 = TESTNET | VERSION_2 # 0x98000002 = -1744830462
|
14
|
-
MAINNET_VERSION_1 = MAINNET | VERSION_1 # 0x68000001 = 1744830465
|
15
|
-
MAINNET_VERSION_2 = MAINNET | VERSION_2 # 0x68000002 = 1744830466
|
16
|
-
|
17
9
|
def self.parse_version(network, version)
|
18
10
|
parse_network(network) | version
|
19
11
|
end
|
data/lib/nem/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nem-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshiyuki Ieyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -316,7 +316,6 @@ files:
|
|
316
316
|
- lib/nem/transaction/provision_namespace.rb
|
317
317
|
- lib/nem/transaction/transfer.rb
|
318
318
|
- lib/nem/util.rb
|
319
|
-
- lib/nem/util/assignable.rb
|
320
319
|
- lib/nem/util/convert.rb
|
321
320
|
- lib/nem/util/deserializer.rb
|
322
321
|
- lib/nem/util/ed25519.rb
|
@@ -347,7 +346,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
347
346
|
version: '0'
|
348
347
|
requirements: []
|
349
348
|
rubyforge_project:
|
350
|
-
rubygems_version: 2.
|
349
|
+
rubygems_version: 2.7.3
|
351
350
|
signing_key:
|
352
351
|
specification_version: 4
|
353
352
|
summary: Ruby gem for communicating with the nem
|
data/lib/nem/util/assignable.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
module Nem
|
2
|
-
module Util
|
3
|
-
module Assignable
|
4
|
-
def initialize(attributes = {})
|
5
|
-
attributes.each do |k, v|
|
6
|
-
send("#{k.to_s}=", v) if respond_to?("#{k.to_s}=")
|
7
|
-
end if attributes
|
8
|
-
yield self if block_given?
|
9
|
-
end
|
10
|
-
|
11
|
-
# @param [Symbol, String] attr Attribute name
|
12
|
-
# @return [Any] Attribute value
|
13
|
-
def [](attr)
|
14
|
-
send(attr)
|
15
|
-
end
|
16
|
-
|
17
|
-
# @return [Hash] Attribute and value pairs
|
18
|
-
def to_hash
|
19
|
-
hashed_properties = instance_variables.each_with_object({}) do |var, hash|
|
20
|
-
hash[var.to_s.delete('@').to_sym] = instance_variable_get(var)
|
21
|
-
end
|
22
|
-
hashnize(hashed_properties)
|
23
|
-
end
|
24
|
-
|
25
|
-
# @return [String] JSON formatted structure
|
26
|
-
def to_json(state = nil)
|
27
|
-
to_hash.to_json(state)
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def hashnize(obj)
|
33
|
-
case true
|
34
|
-
when obj.class.to_s.start_with?('Nem::Unit')
|
35
|
-
obj.to_s
|
36
|
-
when obj.class.to_s.start_with?('Nem::Struct')
|
37
|
-
obj.to_hash
|
38
|
-
when obj.is_a?(Array)
|
39
|
-
obj.map { |el| hashnize(el) }
|
40
|
-
when obj.is_a?(Hash)
|
41
|
-
obj.inject({}) do |hash, (k, v)|
|
42
|
-
hash[k] = hashnize(v)
|
43
|
-
hash
|
44
|
-
end
|
45
|
-
else
|
46
|
-
obj
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|