Class: ZweaBot::Parser
- Inherits:
-
Object
- Object
- ZweaBot::Parser
- Defined in:
- lib/zwea_bot/parser.rb
Constant Summary collapse
- STORES_SHEET =
'Stores'
- DISPLAYS_SHEET =
'Displays'
- ELEMENTS_SHEET =
'Elements'
Instance Attribute Summary collapse
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
- #displays_inventory_headers ⇒ Object
- #displays_inventory_start_column ⇒ Object
- #generate_line_items ⇒ Object
-
#initialize(file) ⇒ Parser
constructor
A new instance of Parser.
- #lines ⇒ Object
- #stores_inventory_headers ⇒ Object
- #stores_inventory_start_column ⇒ Object
Constructor Details
#initialize(file) ⇒ Parser
Returns a new instance of Parser.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/zwea_bot/parser.rb', line 9 def initialize(file) @xlsx = Roo::Spreadsheet.open(file) @warnings = [] validate() store_elements() store_displays() store_stores() generate_line_items() write_report() end |
Instance Attribute Details
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
7 8 9 |
# File 'lib/zwea_bot/parser.rb', line 7 def warnings @warnings end |
Instance Method Details
#displays_inventory_headers ⇒ Object
36 37 38 |
# File 'lib/zwea_bot/parser.rb', line 36 def displays_inventory_headers @displays_inventory_headers ||= grab_inventory_header(name: DISPLAYS_SHEET, start_column: displays_inventory_start_column) end |
#displays_inventory_start_column ⇒ Object
32 33 34 |
# File 'lib/zwea_bot/parser.rb', line 32 def displays_inventory_start_column 2 end |
#generate_line_items ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/zwea_bot/parser.rb', line 20 def generate_line_items Models::Store.all.each do |store| store.installations.each do |installation| installation.display.placements.each do |placement| quantity = installation.quantity * placement.quantity line_item = store.line_items.find_or_create_by(element: placement.element) line_item.increment!(:quantity,quantity) end end end end |
#lines ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/zwea_bot/parser.rb', line 48 def lines l = [] l << '-'*88 l << 'TOTAL ELEMENTS COUNT' Models::Element.all.each do |element| l += element.report_lines end l << '-'*88 Models::Store.all.each do |store| l += store.report_lines end return l end |
#stores_inventory_headers ⇒ Object
44 45 46 |
# File 'lib/zwea_bot/parser.rb', line 44 def stores_inventory_headers @stores_inventory_headers ||= grab_inventory_header(name: STORES_SHEET, start_column: stores_inventory_start_column) end |
#stores_inventory_start_column ⇒ Object
40 41 42 |
# File 'lib/zwea_bot/parser.rb', line 40 def stores_inventory_start_column 6 end |