Class: SOF::Parser
Overview
This class is not intended to be referenced directly. This is an internal implementation of Cycle behavior.
Constant Summary collapse
- PARTS_REGEX =
/ ^(?<vol>V(?<volume>\d*))? # optional volume (?<set>(?<kind>L|C|W|E) # kind (?<period_count>\d+) # period count (?<period_key>D|W|M|Q|Y)?)? # period_key (?<from>F(?<from_date>\d{4}-\d{2}-\d{2}))?$ # optional from /ix
Instance Attribute Summary collapse
-
#match ⇒ Object
readonly
Returns the value of attribute match.
-
#notation ⇒ Object
readonly
Returns the value of attribute notation.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #activated_notation(date) ⇒ Object
- #active? ⇒ Boolean
- #dormant? ⇒ Boolean
- #dormant_capable? ⇒ Boolean
- #from ⇒ Object
- #from_data ⇒ Object
- #from_date ⇒ Object
-
#initialize(notation) ⇒ Parser
constructor
A new instance of Parser.
- #inspect ⇒ Object (also: #to_s)
- #kind ⇒ Object
- #parses?(notation_id) ⇒ Boolean
- #period_count ⇒ Object
- #period_key ⇒ Object
-
#time_span ⇒ Object
Return a TimeSpan object for the period and period_count.
- #to_h ⇒ Object
- #valid? ⇒ Boolean
- #vol ⇒ Object
- #volume ⇒ Object
Constructor Details
#initialize(notation) ⇒ Parser
Returns a new instance of Parser.
41 42 43 44 |
# File 'lib/sof/parser.rb', line 41 def initialize(notation) @notation = notation&.upcase @match = @notation&.match(PARTS_REGEX) end |
Instance Attribute Details
#match ⇒ Object (readonly)
Returns the value of attribute match.
46 47 48 |
# File 'lib/sof/parser.rb', line 46 def match @match end |
#notation ⇒ Object (readonly)
Returns the value of attribute notation.
46 47 48 |
# File 'lib/sof/parser.rb', line 46 def notation @notation end |
Class Method Details
.dormant_capable_kinds ⇒ Object
23 |
# File 'lib/sof/parser.rb', line 23 def self.dormant_capable_kinds = %w[E W] |
.for(notation_or_parser) ⇒ Object
25 26 27 28 29 |
# File 'lib/sof/parser.rb', line 25 def self.for(notation_or_parser) return notation_or_parser if notation_or_parser.is_a? self new(notation_or_parser) end |
.load(hash) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/sof/parser.rb', line 31 def self.load(hash) hash.symbolize_keys! hash.reverse_merge!(volume: 1) keys = i[volume kind period_count period_key] str = "V#{hash.values_at(*keys).join}" return new(str) unless hash[:from_date] new([str, "F#{hash[:from_date]}"].join) end |
Instance Method Details
#==(other) ⇒ Object
67 |
# File 'lib/sof/parser.rb', line 67 def ==(other) = other.to_h == to_h |
#activated_notation(date) ⇒ Object
61 62 63 64 65 |
# File 'lib/sof/parser.rb', line 61 def activated_notation(date) return notation unless dormant_capable? self.class.load(to_h.merge(from_date: date.to_date)).notation end |
#active? ⇒ Boolean
81 |
# File 'lib/sof/parser.rb', line 81 def active? = !dormant? |
#dormant? ⇒ Boolean
83 |
# File 'lib/sof/parser.rb', line 83 def dormant? = dormant_capable? && from_date.nil? |
#dormant_capable? ⇒ Boolean
85 |
# File 'lib/sof/parser.rb', line 85 def dormant_capable? = kind.in?(dormant_capable_kinds) |
#from ⇒ Object
103 |
# File 'lib/sof/parser.rb', line 103 def from = match[:from] |
#from_data ⇒ Object
95 96 97 98 99 |
# File 'lib/sof/parser.rb', line 95 def from_data return {} unless from {from: from} end |
#from_date ⇒ Object
101 |
# File 'lib/sof/parser.rb', line 101 def from_date = match[:from_date] |
#inspect ⇒ Object Also known as: to_s
58 |
# File 'lib/sof/parser.rb', line 58 def inspect = notation |
#kind ⇒ Object
105 |
# File 'lib/sof/parser.rb', line 105 def kind = match[:kind] |
#parses?(notation_id) ⇒ Boolean
79 |
# File 'lib/sof/parser.rb', line 79 def parses?(notation_id) = kind == notation_id |
#period_count ⇒ Object
87 |
# File 'lib/sof/parser.rb', line 87 def period_count = match[:period_count] |
#period_key ⇒ Object
89 |
# File 'lib/sof/parser.rb', line 89 def period_key = match[:period_key] |
#time_span ⇒ Object
Return a TimeSpan object for the period and period_count
52 53 54 |
# File 'lib/sof/parser.rb', line 52 def time_span @time_span ||= TimeSpan.for(period_count, period_key) end |
#to_h ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/sof/parser.rb', line 69 def to_h { volume:, kind:, period_count:, period_key:, from_date: } end |
#valid? ⇒ Boolean
56 |
# File 'lib/sof/parser.rb', line 56 def valid? = match.present? |
#vol ⇒ Object
91 |
# File 'lib/sof/parser.rb', line 91 def vol = match[:vol] || "V1" |
#volume ⇒ Object
93 |
# File 'lib/sof/parser.rb', line 93 def volume = (match[:volume] || 1).to_i |