Class: Sports::Country
- Inherits:
-
Object
- Object
- Sports::Country
- Includes:
- SportDb::NameHelper
- Defined in:
- lib/sportdb/structs/country.rb
Constant Summary collapse
- IS_CODE_N_NAME_RE =
only allow asci a to z in code & name for now - why? why not?
e.g. USA, etc. %r{^ [A-Z]+ $}x
- IS_CODE_RE =
e.g. nirl, a, ö, etc.
%r{^ [\p{Ll}]+ $}x
- ADJ =
country adjectives - quick hack for now inline here
todo - add language marker - why? why not` e.g. Österr. => Österr. [de] Deutsche` => Deutsche [de]todo/fix - add more - see
https://en.wikipedia.org/wiki/List_of_adjectival_and_demonymic_forms_for_countries_and_nations { 'at' => ['Österr.', 'Austrian'], 'de' => ['Deutsche', 'German'], 'eng' => ['English'], 'sco' => ['Scottish'], 'wal' => ['Welsh'], 'nir' => ['Northern Irish'], 'ie' => ['Irish'], 'it' => ['Italian'], 'sm' => ['San Marinese'], 'fr' => ['French'], 'hu' => ['Hungarian'], 'gr' => ['Greek'], 'pt' => ['Portuguese'], 'ch' => ['Swiss'], 'tr' => ['Turkish'], }
Constants included from SportDb::NameHelper
SportDb::NameHelper::LANG_RE, SportDb::NameHelper::NORM_RE, SportDb::NameHelper::YEAR_RE
Instance Attribute Summary collapse
-
#alt_names ⇒ Object
Returns the value of attribute alt_names.
-
#code ⇒ Object
readonly
note: is read-only/immutable for now - why? why not? add cities (array/list) - why? why not?.
-
#key ⇒ Object
readonly
note: is read-only/immutable for now - why? why not? add cities (array/list) - why? why not?.
-
#name ⇒ Object
readonly
note: is read-only/immutable for now - why? why not? add cities (array/list) - why? why not?.
-
#tags ⇒ Object
readonly
note: is read-only/immutable for now - why? why not? add cities (array/list) - why? why not?.
Instance Method Summary collapse
-
#adjective ⇒ Object
(also: #adj)
note - adjective might be nil!!!.
- #adjectives ⇒ Object (also: #adjs)
- #codes ⇒ Object
-
#initialize(key: nil, name:, code:, tags: []) ⇒ Country
constructor
A new instance of Country.
- #names ⇒ Object
- #pretty_print(printer) ⇒ Object
Methods included from SportDb::NameHelper
#has_lang?, #has_year?, #normalize, #sanitize, #strip_lang, #strip_norm, #strip_year, #variants
Constructor Details
#initialize(key: nil, name:, code:, tags: []) ⇒ Country
Returns a new instance of Country.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sportdb/structs/country.rb', line 34 def initialize( key: nil, name:, code:, tags: [] ) ## note: auto-generate key "on-the-fly" if missing for now - why? why not? ## note: quick hack - auto-generate key, that is, remove all non-ascii chars and downcase @key = begin if key key elsif code code.downcase else unaccent( name ).downcase.gsub( /[^a-z]/, '' ) end end @name, @code = name, code @alt_names = [] = end |
Instance Attribute Details
#alt_names ⇒ Object
Returns the value of attribute alt_names.
32 33 34 |
# File 'lib/sportdb/structs/country.rb', line 32 def alt_names @alt_names end |
#code ⇒ Object (readonly)
note: is read-only/immutable for now - why? why not?
add cities (array/list) - why? why not?
31 32 33 |
# File 'lib/sportdb/structs/country.rb', line 31 def code @code end |
#key ⇒ Object (readonly)
note: is read-only/immutable for now - why? why not?
add cities (array/list) - why? why not?
31 32 33 |
# File 'lib/sportdb/structs/country.rb', line 31 def key @key end |
#name ⇒ Object (readonly)
note: is read-only/immutable for now - why? why not?
add cities (array/list) - why? why not?
31 32 33 |
# File 'lib/sportdb/structs/country.rb', line 31 def name @name end |
#tags ⇒ Object (readonly)
note: is read-only/immutable for now - why? why not?
add cities (array/list) - why? why not?
31 32 33 |
# File 'lib/sportdb/structs/country.rb', line 31 def end |
Instance Method Details
#adjective ⇒ Object Also known as: adj
note - adjective might be nil!!!
140 |
# File 'lib/sportdb/structs/country.rb', line 140 def adjective() adjectives[0]; end |
#adjectives ⇒ Object Also known as: adjs
141 |
# File 'lib/sportdb/structs/country.rb', line 141 def adjectives() ADJ[@key] || []; end |
#codes ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/sportdb/structs/country.rb', line 79 def codes ## note - "auto-magically" downcase code (and code'n'name matches)!!! codes = [@key, @code.downcase] alt_names.each do |name| if IS_CODE_N_NAME_RE.match?( name ) codes << name.downcase elsif IS_CODE_RE.match?( name ) codes << name else ## assume name ## do nothing - skip/ignore end end codes.uniq end |
#names ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/sportdb/structs/country.rb', line 97 def names names = [@name] alt_names.each do |name| if IS_CODE_N_NAME_RE.match?( name ) names << name elsif IS_CODE_RE.match?( name ) ## do nothing - skip/ignore else ## assume name names << strip_lang( name ) end end names.uniq end |
#pretty_print(printer) ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/sportdb/structs/country.rb', line 146 def pretty_print( printer ) buf = String.new buf << "<Country: #{@key} - #{@name} (#{@code})" buf << "|#{@alt_names.join('|')}" if @alt_names && !@alt_names.empty? buf << ", #{@tags.join('|')})" if && !.empty? buf << ">" printer.text( buf ) end |