Class: UncleKryon::Language
- Defined in:
- lib/unclekryon/iso/language.rb
Instance Attribute Summary collapse
-
#alpha2_code ⇒ Object
readonly
Returns the value of attribute alpha2_code.
-
#alpha3_code ⇒ Object
readonly
Returns the value of attribute alpha3_code.
-
#alpha3_code_b ⇒ Object
readonly
Returns the value of attribute alpha3_code_b.
-
#codes ⇒ Object
readonly
Returns the value of attribute codes.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
Attributes inherited from BaseIso
Attributes inherited from BaseData
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(row = nil) ⇒ Language
constructor
A new instance of Language.
- #to_s ⇒ Object
Methods inherited from BaseIso
fix_name, flip_word_order, simplify_code, simplify_name
Methods inherited from BaseData
#initialize_copy, #max_updated_on, max_updated_on, #max_updated_on_s, max_updated_on_s, #update
Constructor Details
#initialize(row = nil) ⇒ Language
Returns a new instance of Language.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/unclekryon/iso/language.rb', line 34 def initialize(row=nil) super() @names = nil @codes = nil @alpha2_code = nil @alpha3_code = nil @alpha3_code_b = nil if row.is_a?(Array) @names = row[2].split(';').compact.uniq.map(&self.class.method(:fix_name)) @alpha2_code = row[1].empty? ? nil : row[1] @alpha3_code = row[0].split(/[[:space:]]*[\(\)][[:space:]]*/) if @alpha3_code.length <= 1 @alpha3_code = row[0] else prev_was_tag = true @alpha3_code.each_with_index do |c,i| c.strip! c_up = c.upcase if c_up == 'B' || c_up == 'T' if prev_was_tag raise "Invalid alpha-3 code for: #{@names},#{@alpha2_code},#{@alpha3_code}" end case c_up when 'B' raise "Multiple alpha3_code_b: #{@alpha3_code}" unless @alpha3_code_b.nil? @alpha3_code_b = @alpha3_code[i - 1] when 'T' raise "Multiple alpha3_code (T): #{@alpha3_code}" unless @alpha3_code.is_a?(Array) @alpha3_code = @alpha3_code[i - 1] end prev_was_tag = true else prev_was_tag = false end end # Wasn't set in the above loop? if @alpha3_code.is_a?(Array) raise "Invalid alpha-3 code for: #{@names},#{@alpha2_code},#{@alpha3_code}" end end @name = @names[0] #@names = @names @code = @alpha3_code @codes = [@alpha3_code,@alpha3_code_b,@alpha2_code].compact.uniq end end |
Instance Attribute Details
#alpha2_code ⇒ Object (readonly)
Returns the value of attribute alpha2_code.
30 31 32 |
# File 'lib/unclekryon/iso/language.rb', line 30 def alpha2_code @alpha2_code end |
#alpha3_code ⇒ Object (readonly)
Returns the value of attribute alpha3_code.
31 32 33 |
# File 'lib/unclekryon/iso/language.rb', line 31 def alpha3_code @alpha3_code end |
#alpha3_code_b ⇒ Object (readonly)
Returns the value of attribute alpha3_code_b.
32 33 34 |
# File 'lib/unclekryon/iso/language.rb', line 32 def alpha3_code_b @alpha3_code_b end |
#codes ⇒ Object (readonly)
Returns the value of attribute codes.
29 30 31 |
# File 'lib/unclekryon/iso/language.rb', line 29 def codes @codes end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
28 29 30 |
# File 'lib/unclekryon/iso/language.rb', line 28 def names @names end |
Instance Method Details
#==(other) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/unclekryon/iso/language.rb', line 91 def ==(other) return super(other) && @names == other.names && @codes == other.codes && @alpha2_code == other.alpha2_code && @alpha3_code == other.alpha3_code && @alpha3_code_b == other.alpha3_code_b end |
#to_s ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/unclekryon/iso/language.rb', line 100 def to_s s = '['.dup s << %Q("#{@name}","#{@names.join(';')}",) s << %Q(#{@code},"#{@codes.join(';')}",) s << "#{@alpha2_code},#{@alpha3_code},#{@alpha3_code_b}" s << ']' return s end |