Class: Sports::Country

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/structs/country.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: nil, name:, code:, tags: []) ⇒ Country

Returns a new instance of Country.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sportdb/structs/country.rb', line 33

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      = []
  @tags           = tags
end

Instance Attribute Details

#alt_namesObject

Returns the value of attribute alt_names.



31
32
33
# File 'lib/sportdb/structs/country.rb', line 31

def alt_names
  @alt_names
end

#codeObject (readonly)

note: is read-only/immutable for now - why? why not?

add cities (array/list) - why? why not?


30
31
32
# File 'lib/sportdb/structs/country.rb', line 30

def code
  @code
end

#keyObject (readonly)

note: is read-only/immutable for now - why? why not?

add cities (array/list) - why? why not?


30
31
32
# File 'lib/sportdb/structs/country.rb', line 30

def key
  @key
end

#nameObject (readonly)

note: is read-only/immutable for now - why? why not?

add cities (array/list) - why? why not?


30
31
32
# File 'lib/sportdb/structs/country.rb', line 30

def name
  @name
end

#tagsObject (readonly)

note: is read-only/immutable for now - why? why not?

add cities (array/list) - why? why not?


30
31
32
# File 'lib/sportdb/structs/country.rb', line 30

def tags
  @tags
end

Instance Method Details

#pretty_print(printer) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/sportdb/structs/country.rb', line 50

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 @tags && !@tags.empty?
  buf << ">"

  printer.text( buf ) 
end