Class: Official
Constant Summary collapse
- TYPE_OFFICIAL =
{ 1 => 'Referee', 2 => 'Assistant Referee 1', 3 => 'Assistant Referee 2', }
Instance Attribute Summary collapse
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
._build_ary(recs) ⇒ Object
use referees?.
- .build(h) ⇒ Object
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(id:, name:, country:, type:) ⇒ Official
constructor
A new instance of Official.
Constructor Details
#initialize(id:, name:, country:, type:) ⇒ Official
Returns a new instance of Official.
104 105 106 107 108 109 |
# File 'lib/fifadat/models/official.rb', line 104 def initialize( id:, name:, country:, type:) @id = id @name = name @country = country @type = type end |
Instance Attribute Details
#country ⇒ Object (readonly)
Returns the value of attribute country.
102 103 104 |
# File 'lib/fifadat/models/official.rb', line 102 def country @country end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
102 103 104 |
# File 'lib/fifadat/models/official.rb', line 102 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
102 103 104 |
# File 'lib/fifadat/models/official.rb', line 102 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
102 103 104 |
# File 'lib/fifadat/models/official.rb', line 102 def type @type end |
Class Method Details
._build_ary(recs) ⇒ Object
use referees?
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/fifadat/models/official.rb', line 78 def self._build_ary( recs ) ## use referees? ## skip fourth official (4) for now recs = recs.select { |h| [1,2,3].include?( h['OfficialType'] ) } ## sort by type 1/2/3 ## 1 - referee ## 2 - assistant referee 1 ## 3 - assistant referee 2 ## 4 - fourth official ## 5 - video assistant referee (var) ## 6 - reserve referee ## 7 - offside var ## 8 - assistant var ## 9 - support var ## 10 - reserve assistant referee recs = recs.sort { |l,r| l['OfficialType'] <=> r['OfficialType'] } recs = recs.map { |h| build( h ) } recs end |
.build(h) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fifadat/models/official.rb', line 56 def self.build( h ) name = desc( h['Name'] ) ## fix - use norm_official ## name = norm_official( name ) idCountry = h['IdCountry'] type = h['OfficialType'] assert( is_alpha?(name), "official name alpha expected; got #{pp_alpha(name)}" ) assert( [1,2,3,4,5,6,7,8,9,10].include?( type ), "official type 1/2/3/4/5/6/7/8/9/10 expected; got #{type}" ) rec = { id: h['OfficialId'], name: name, country: idCountry, type: TYPE_OFFICIAL[type] ## change type to literal string } new(**rec) end |
Instance Method Details
#as_json ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/fifadat/models/official.rb', line 111 def as_json(*) h = { 'name' => name, 'country' => country, 'type' => type, } h end |