Class: Kokki::Converter
- Inherits:
-
Object
- Object
- Kokki::Converter
- Defined in:
- lib/kokki/converter.rb
Instance Attribute Summary collapse
-
#dict ⇒ Object
readonly
Returns the value of attribute dict.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#upcase ⇒ Object
readonly
Returns the value of attribute upcase.
Class Method Summary collapse
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(input) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(input) ⇒ Converter
Returns a new instance of Converter.
9 10 11 12 13 |
# File 'lib/kokki/converter.rb', line 9 def initialize(input) @input = input @upcase = input.upcase @dict = Dictionary.new end |
Instance Attribute Details
#dict ⇒ Object (readonly)
Returns the value of attribute dict.
7 8 9 |
# File 'lib/kokki/converter.rb', line 7 def dict @dict end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
7 8 9 |
# File 'lib/kokki/converter.rb', line 7 def input @input end |
#upcase ⇒ Object (readonly)
Returns the value of attribute upcase.
7 8 9 |
# File 'lib/kokki/converter.rb', line 7 def upcase @upcase end |
Class Method Details
.convert(input) ⇒ Object
28 29 30 |
# File 'lib/kokki/converter.rb', line 28 def self.convert(input) new(input).convert end |
Instance Method Details
#convert ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/kokki/converter.rb', line 15 def convert flag = nil flag = dict.lookup_by_alpha_2_code(upcase) if input.length == 2 flag = dict.lookup_by_alpha_3_code(upcase) if input.length == 3 flag ||= dict.lookup_by_name(upcase) flag ||= convert_as_ip_address(input) raise InvalidInputError, "invalid input: #{input}" unless flag flag end |