Class: Stage
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#end_date ⇒ Object
readonly
note - seq might be same for different stages e.g.
-
#level ⇒ Object
readonly
note - seq might be same for different stages e.g.
-
#name ⇒ Object
readonly
note - seq might be same for different stages e.g.
-
#seq ⇒ Object
readonly
note - seq might be same for different stages e.g.
-
#start_date ⇒ Object
readonly
note - seq might be same for different stages e.g.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(name:, seq:, level: nil, start_date: nil, end_date: nil) ⇒ Stage
constructor
A new instance of Stage.
Constructor Details
#initialize(name:, seq:, level: nil, start_date: nil, end_date: nil) ⇒ Stage
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/fifadat/models/stage.rb', line 70 def initialize( name:, seq:, level: nil, start_date: nil, end_date: nil ) @name = name @seq = seq # e.g. 1,2,3,4,5 @start_date = start_date @end_date = end_date @level = level @count = 0 ## match (usage/reference) count(er) end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
68 69 70 |
# File 'lib/fifadat/models/stage.rb', line 68 def count @count end |
#end_date ⇒ Object (readonly)
note - seq might be same for different stages e.g. "seq": 2, "name": "Relegation Round",
"seq": 2,
"name": "Championship Round",
65 66 67 |
# File 'lib/fifadat/models/stage.rb', line 65 def end_date @end_date end |
#level ⇒ Object (readonly)
note - seq might be same for different stages e.g. "seq": 2, "name": "Relegation Round",
"seq": 2,
"name": "Championship Round",
65 66 67 |
# File 'lib/fifadat/models/stage.rb', line 65 def level @level end |
#name ⇒ Object (readonly)
note - seq might be same for different stages e.g. "seq": 2, "name": "Relegation Round",
"seq": 2,
"name": "Championship Round",
65 66 67 |
# File 'lib/fifadat/models/stage.rb', line 65 def name @name end |
#seq ⇒ Object (readonly)
note - seq might be same for different stages e.g. "seq": 2, "name": "Relegation Round",
"seq": 2,
"name": "Championship Round",
65 66 67 |
# File 'lib/fifadat/models/stage.rb', line 65 def seq @seq end |
#start_date ⇒ Object (readonly)
note - seq might be same for different stages e.g. "seq": 2, "name": "Relegation Round",
"seq": 2,
"name": "Championship Round",
65 66 67 |
# File 'lib/fifadat/models/stage.rb', line 65 def start_date @start_date end |
Class Method Details
.build(h) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fifadat/models/stage.rb', line 21 def self.build( h ) name = desc( h['Name'] ) seq = h['SequenceOrder'] level = h['StageLevel'] ## note - is optional start_date = nil end_date = nil if h['StartDate'] && h['EndDate'] ## note - start/end dates are utc (NOT local) start_date = parse_date_utc( h['StartDate'] ) ## expects ...:00Z format end_date = parse_date_utc( h['EndDate'] ) ## expects ...:00Z format ## check if HH::MM is 00:00 ## only use date for now; ignore time ## report warn(ing) if time present!!! if start_date.hour != 0 || start_date.min != 0 || end_date.hour != 0 || end_date.min != 0 ## issue warn start/end_date with HH:MM (NOT 00:00) puts "!! warn: stage start/end_date with HH:MM (expected 00:00)" pp h end else ## maybe add to log later - why? why not? ## puts "!! warn: stage witouout start/end_date" ## pp h end new( name: name, seq: seq, start_date: start_date ? start_date.to_date : nil, end_date: end_date ? end_date.to_date : nil, level: level ) end |
Instance Method Details
#as_json ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fifadat/models/stage.rb', line 84 def as_json(*) h = { 'seq' => seq, 'name' => name } h['start_date'] = start_date.strftime('%Y-%m-%d') if start_date h['end_date'] = end_date.strftime('%Y-%m-%d') if end_date h['level'] = level if level h['count'] = count h end |