Class: UncleKryon::BaseIso

Inherits:
BaseData show all
Defined in:
lib/unclekryon/iso/base_iso.rb

Direct Known Subclasses

CanProvTerr, Country, Language, Region, Subregion, UsaState

Instance Attribute Summary collapse

Attributes inherited from BaseData

#updated_on

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseData

#initialize_copy, #max_updated_on, max_updated_on, #max_updated_on_s, max_updated_on_s, #update

Constructor Details

#initializeBaseIso

Returns a new instance of BaseIso.



24
25
26
27
28
29
# File 'lib/unclekryon/iso/base_iso.rb', line 24

def initialize
  super()

  @name = nil
  @code = nil
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



22
23
24
# File 'lib/unclekryon/iso/base_iso.rb', line 22

def code
  @code
end

#nameObject (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/unclekryon/iso/base_iso.rb', line 21

def name
  @name
end

Class Method Details

.fix_name(name) ⇒ Object



31
32
33
# File 'lib/unclekryon/iso/base_iso.rb', line 31

def self.fix_name(name)
  return flip_word_order(simplify_name(name))
end

.flip_word_order(word) ⇒ Object



35
36
37
38
# File 'lib/unclekryon/iso/base_iso.rb', line 35

def self.flip_word_order(word)
  # e.g., change 'English, Old' to 'Old English'
  return word.gsub(/([^\,\;]+)[[:space:]]*[\,\;]+[[:space:]]*([^\,\;]+)/,'\\2 \\1').strip
end

.simplify_code(code) ⇒ Object



40
41
42
43
# File 'lib/unclekryon/iso/base_iso.rb', line 40

def self.simplify_code(code)
  # e.g., remove 'US-' from 'US-AL'
  return code.gsub(/[[:alnum:][:space:]]+\-[[:space:]]*/,'').strip
end

.simplify_name(name) ⇒ Object



45
46
47
48
# File 'lib/unclekryon/iso/base_iso.rb', line 45

def self.simplify_name(name)
  # e.g., remove '(the)' from 'United States of America (the)'
  return name.gsub(/[[:space:]]*\([^\)]*\)[[:space:]]*/,'').strip
end

Instance Method Details

#==(other) ⇒ Object



50
51
52
# File 'lib/unclekryon/iso/base_iso.rb', line 50

def ==(other)
  return @name == other.name && @code == other.code
end

#to_sObject



54
55
56
# File 'lib/unclekryon/iso/base_iso.rb', line 54

def to_s
  return %Q(["#{@name}",#{@code}])
end