Class: NEAR::Action
- Inherits:
-
Object
- Object
- NEAR::Action
- Defined in:
- lib/near/action.rb
Overview
Represents a NEAR action.
Direct Known Subclasses
AddKey, CreateAccount, Delegate, DeleteAccount, DeleteKey, DeployContract, FunctionCall, Stake, Transfer
Defined Under Namespace
Classes: AddKey, CreateAccount, Delegate, DeleteAccount, DeleteKey, DeployContract, FunctionCall, Stake, Transfer
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
The action data.
- #type ⇒ Symbol readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data = nil) ⇒ Action
constructor
A new instance of Action.
- #inspect ⇒ String
- #to_h ⇒ Hash
- #to_sym ⇒ Symbol
Constructor Details
#initialize(data = nil) ⇒ Action
Returns a new instance of Action.
109 110 111 |
# File 'lib/near/action.rb', line 109 def initialize(data = nil) @data = data.to_h if data end |
Instance Attribute Details
#data ⇒ Hash (readonly)
The action data.
124 125 126 |
# File 'lib/near/action.rb', line 124 def data @data end |
#type ⇒ Symbol (readonly)
115 116 117 |
# File 'lib/near/action.rb', line 115 def type @type end |
Class Method Details
.parse(data) ⇒ NEAR::Action
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/near/action.rb', line 80 def self.parse(data) case when data.is_a?(String) then case when 'CreateAccount' then CreateAccount.new when 'DeployContract' then DeployContract.new when 'FunctionCall' then FunctionCall.new when 'Transfer' then Transfer.new when 'Stake' then Stake.new when 'AddKey' then AddKey.new when 'DeleteKey' then DeleteKey.new when 'DeleteAccount' then DeleteAccount.new when 'Delegate' then Delegate.new else self.new end when data['CreateAccount'] then CreateAccount.new(data['CreateAccount']) when data['DeployContract'] then DeployContract.new(data['DeployContract']) when data['FunctionCall'] then FunctionCall.new(data['FunctionCall']) when data['Transfer'] then Transfer.new(data['Transfer']) when data['Stake'] then Stake.new(data['Stake']) when data['AddKey'] then AddKey.new(data['AddKey']) when data['DeleteKey'] then DeleteKey.new(data['DeleteKey']) when data['DeleteAccount'] then DeleteAccount.new(data['DeleteAccount']) when data['Delegate'] then Delegate.new(data['Delegate']) else self.new(data[data.keys.first]) end end |
Instance Method Details
#inspect ⇒ String
136 137 138 139 140 |
# File 'lib/near/action.rb', line 136 def inspect data = self.to_h data['args'] = '...' if data['args'] "#<#{self.class.name} #{data.to_json}>" end |
#to_h ⇒ Hash
128 |
# File 'lib/near/action.rb', line 128 def to_h; @data || {}; end |
#to_sym ⇒ Symbol
132 |
# File 'lib/near/action.rb', line 132 def to_sym; self.type; end |