Class: OrcaApi::Result
- Inherits:
-
Object
show all
- Defined in:
- lib/orca_api/result.rb
Overview
Direct Known Subclasses
AcceptanceService::ListResult, FindService::FindResult, FormResult, LockService::ListResult, MedicalPracticeService::EmptyDeleteNumberInfoError, MedicalPracticeService::ResponseResult, MedicalPracticeService::UnselectedError, PatientService::AccidentInsurance::UnselectedError, PatientService::CreateResult, PatientService::HealthPublicInsuranceCommon::Result, OrcaApi::ReceiptDataCheckService::CreatedResult, OrcaApi::ReceiptDataCheckService::ListEffectiveInformationResult, OrcaApi::ReceiptDataService::CreatedResult, OrcaApi::ReceiptDataService::ListEffectiveInformationResult, OrcaApi::ReceiptService::CheckResult, StatisticsFormService::CreateResult, StatisticsFormService::CreatedResult, StatisticsFormService::ListResult, SubjectiveService::Result
Direct Known Subclasses
AcceptanceService::ListResult, FindService::FindResult, FormResult, LockService::ListResult, MedicalPracticeService::EmptyDeleteNumberInfoError, MedicalPracticeService::ResponseResult, MedicalPracticeService::UnselectedError, PatientService::AccidentInsurance::UnselectedError, PatientService::CreateResult, PatientService::HealthPublicInsuranceCommon::Result, OrcaApi::ReceiptDataCheckService::CreatedResult, OrcaApi::ReceiptDataCheckService::ListEffectiveInformationResult, OrcaApi::ReceiptDataService::CreatedResult, OrcaApi::ReceiptDataService::ListEffectiveInformationResult, OrcaApi::ReceiptService::CheckResult, StatisticsFormService::CreateResult, StatisticsFormService::CreatedResult, StatisticsFormService::ListResult, SubjectiveService::Result
Constant Summary
- LOCKED_API_RESULT =
Set.new(%w(E90 E9999))
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(raw) ⇒ Result
Returns a new instance of Result
65
66
67
68
69
70
|
# File 'lib/orca_api/result.rb', line 65
def initialize(raw)
@raw = raw
@attr_names = body.keys.map { |key|
[Client.underscore(key).to_sym, key]
}.to_h
end
|
Constructor Details
#initialize(raw) ⇒ Result
Returns a new instance of Result
65
66
67
68
69
70
|
# File 'lib/orca_api/result.rb', line 65
def initialize(raw)
@raw = raw
@attr_names = body.keys.map { |key|
[Client.underscore(key).to_sym, key]
}.to_h
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/orca_api/result.rb', line 100
def method_missing(symbol, *args)
if (key = @attr_names[symbol])
body[key]
else
super
end
end
|
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
63
64
65
|
# File 'lib/orca_api/result.rb', line 63
def raw
@raw
end
|
Class Method Details
.def_info(name, *path) ⇒ Array<Array, Hash>
深いパスのレスポンスボディに対するアクセサーを定義するメソッド
57
58
59
60
61
|
# File 'lib/orca_api/result.rb', line 57
def self.def_info(name, *path)
define_method name do
Array(body.dig(*path))
end
end
|
.parse(raw) ⇒ Object
23
24
25
|
# File 'lib/orca_api/result.rb', line 23
def self.parse(raw)
trim_response(JSON.parse(raw)).first[1]
end
|
.trim_response(hash) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/orca_api/result.rb', line 8
def self.trim_response(hash)
result = {}
hash.each do |k, v|
result[k] = case v
when Hash
trim_response(v)
when Array
v.reverse_each.drop_while(&:empty?).reverse.map { |e| trim_response(e) }
else
v
end
end
result
end
|
Instance Method Details
#[](key) ⇒ Object
76
77
78
|
# File 'lib/orca_api/result.rb', line 76
def [](key)
body[key]
end
|
#body ⇒ Object
72
73
74
|
# File 'lib/orca_api/result.rb', line 72
def body
@body ||= self.class.parse(@raw)
end
|
#locked? ⇒ Boolean
92
93
94
|
# File 'lib/orca_api/result.rb', line 92
def locked?
LOCKED_API_RESULT.include?(api_result)
end
|
#message ⇒ Object
96
97
98
|
# File 'lib/orca_api/result.rb', line 96
def message
"#{api_result_message}(#{api_result})"
end
|
#ok? ⇒ Boolean
Api_Resultが00、0000、W00といった処理完了を示す値である場合にtrueを返す
84
85
86
|
# File 'lib/orca_api/result.rb', line 84
def ok?
/\AW?0+\z/.match? api_result
end
|
#respond_to_missing?(symbol, arg) ⇒ Boolean
108
109
110
111
112
113
114
|
# File 'lib/orca_api/result.rb', line 108
def respond_to_missing?(symbol, arg)
if @attr_names.key?(symbol)
true
else
super
end
end
|
#warning? ⇒ Boolean
88
89
90
|
# File 'lib/orca_api/result.rb', line 88
def warning?
/\AW/.match? api_result
end
|