Class: Lpgrid::InputReader
- Inherits:
-
Object
- Object
- Lpgrid::InputReader
- Defined in:
- lib/lpgrid/input_reader.rb
Constant Summary collapse
- IncorectInputFormat =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Class Method Summary collapse
Instance Method Summary collapse
- #check_format ⇒ Object
-
#initialize(string) ⇒ InputReader
constructor
A new instance of InputReader.
- #splitter ⇒ Object
- #translate ⇒ Object
Constructor Details
#initialize(string) ⇒ InputReader
Returns a new instance of InputReader.
13 14 15 |
# File 'lib/lpgrid/input_reader.rb', line 13 def initialize(string) @string = string end |
Instance Attribute Details
#string ⇒ Object (readonly)
Returns the value of attribute string.
5 6 7 |
# File 'lib/lpgrid/input_reader.rb', line 5 def string @string end |
Class Method Details
.translate(string) ⇒ Object
7 8 9 10 11 |
# File 'lib/lpgrid/input_reader.rb', line 7 def self.translate(string) instance = new(string) instance.check_format instance.translate end |
Instance Method Details
#check_format ⇒ Object
17 18 19 20 21 |
# File 'lib/lpgrid/input_reader.rb', line 17 def check_format if splitter.collect(&:length).select { |leng| leng !=2 } .any? raise IncorectInputFormat end end |
#splitter ⇒ Object
29 30 31 |
# File 'lib/lpgrid/input_reader.rb', line 29 def splitter string.split(' ') end |
#translate ⇒ Object
23 24 25 26 27 |
# File 'lib/lpgrid/input_reader.rb', line 23 def translate splitter.collect do |element| Grid.new(element).fetch end.join(' ') end |