Class: JMAFeed::RiskLevel
- Inherits:
-
Object
- Object
- JMAFeed::RiskLevel
- Defined in:
- lib/jma_feed/entity/risk_level.rb
Constant Summary collapse
- LIST =
大雨危険度通知_解説資料.pdf > 別表3 「危険度分布の危険度」コード表
{ level0: ['00'], # 今後の情報等に留意 level1: ['11', '13'], # 警戒レベル1(心構えを高める), 早期注意情報 level2: ['21', '22', '23', '24'], # 警戒レベル2(避難行動の確認)相当, 注意報 level3: ['31', '32', '33', '34'], # 警戒レベル3(高齢者等避難)相当, 警報 level4: ['41', '42', '43', '44'], # 警戒レベル4(避難)相当, 危険 level5: ['51', '52', '53', '54'], # 警戒レベル5(災害切迫)相当, 災害発生のおそれ }
Instance Attribute Summary collapse
-
#codes ⇒ Object
readonly
Returns the value of attribute codes.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id, codes) ⇒ RiskLevel
constructor
A new instance of RiskLevel.
- #intensity ⇒ Object
- #risk_include?(code) ⇒ Boolean
Constructor Details
#initialize(id, codes) ⇒ RiskLevel
Returns a new instance of RiskLevel.
31 32 33 34 |
# File 'lib/jma_feed/entity/risk_level.rb', line 31 def initialize(id, codes) @id = id.to_sym @codes = codes end |
Instance Attribute Details
#codes ⇒ Object (readonly)
Returns the value of attribute codes.
30 31 32 |
# File 'lib/jma_feed/entity/risk_level.rb', line 30 def codes @codes end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
30 31 32 |
# File 'lib/jma_feed/entity/risk_level.rb', line 30 def id @id end |
Class Method Details
.all ⇒ Object
15 16 17 |
# File 'lib/jma_feed/entity/risk_level.rb', line 15 def self.all @all ||= LIST.map{|k,v| new(k, v)} end |
.find(id) ⇒ Object
19 20 21 |
# File 'lib/jma_feed/entity/risk_level.rb', line 19 def self.find(id) all.find{|l| l.id == id.to_sym} end |
.greater_than(level) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/jma_feed/entity/risk_level.rb', line 23 def self.greater_than(level) level = (level.is_a?(Symbol) or level.is_a?(String)) ? find(level) : level all.select{|l| l.intensity >= level.intensity} end |
Instance Method Details
#intensity ⇒ Object
36 37 38 |
# File 'lib/jma_feed/entity/risk_level.rb', line 36 def intensity @intensity ||= id.to_s.sub('level', '').to_i end |
#risk_include?(code) ⇒ Boolean
40 41 42 43 |
# File 'lib/jma_feed/entity/risk_level.rb', line 40 def risk_include?(code) risk_codes = self.class.greater_than(self).map(&:codes).flatten risk_codes.include?(code) end |