Class: CrazyTrain::OrderParser
- Inherits:
-
Object
- Object
- CrazyTrain::OrderParser
- Defined in:
- app/models/crazy_train/order_parser.rb
Instance Attribute Summary collapse
-
#orders ⇒ Object
readonly
Returns the value of attribute orders.
Instance Method Summary collapse
-
#initialize(order_text) ⇒ OrderParser
constructor
A new instance of OrderParser.
- #parse! ⇒ Object
Constructor Details
#initialize(order_text) ⇒ OrderParser
Returns a new instance of OrderParser.
5 6 7 8 |
# File 'app/models/crazy_train/order_parser.rb', line 5 def initialize(order_text) @order_text = order_text @orders = {} end |
Instance Attribute Details
#orders ⇒ Object (readonly)
Returns the value of attribute orders.
3 4 5 |
# File 'app/models/crazy_train/order_parser.rb', line 3 def orders @orders end |
Instance Method Details
#parse! ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/models/crazy_train/order_parser.rb', line 10 def parse! @order_text.split(',').map do |text| name, direction = text.split('.') direction ||= 'asc' @orders[name] = direction end end |