Class: PostCL::Store
- Inherits:
-
Object
- Object
- PostCL::Store
- Defined in:
- lib/postcl/store.rb
Instance Method Summary collapse
- #add(resp) ⇒ Object
- #filter(f_proc) ⇒ Object
- #include?(barcode, postcode) ⇒ Boolean
-
#initialize(session, name = "store.yaml", dir = "#{File.expand_path('~')}/.config/postcl/") ⇒ Store
constructor
A new instance of Store.
- #package(barcode, postcode) ⇒ Object
- #packages ⇒ Object
- #postcode ⇒ Object
- #postcode=(postcode) ⇒ Object
- #prompt_add(resp) ⇒ Object
- #promt_list ⇒ Object
- #undelivered ⇒ Object
Constructor Details
#initialize(session, name = "store.yaml", dir = "#{File.expand_path('~')}/.config/postcl/") ⇒ Store
Returns a new instance of Store.
2 3 4 5 6 7 8 9 10 |
# File 'lib/postcl/store.rb', line 2 def initialize(session, name = "store.yaml", dir = "#{File.('~')}/.config/postcl/") @session = session @args = session.args @prompt = session.prompt @dir = dir @path = dir + name load end |
Instance Method Details
#add(resp) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/postcl/store.rb', line 30 def add(resp) p_elem = { barcode: resp.info[:barcode], postcode: resp.info[:postalCode], undelivered: resp.info[:delivery][:isDelivered] } @data[:packages] << p_elem save end |
#filter(f_proc) ⇒ Object
53 54 55 |
# File 'lib/postcl/store.rb', line 53 def filter(f_proc) @data[:packages].select(&f_proc) end |
#include?(barcode, postcode) ⇒ Boolean
65 66 67 |
# File 'lib/postcl/store.rb', line 65 def include?(, postcode) package(, postcode) != nil end |
#package(barcode, postcode) ⇒ Object
61 62 63 |
# File 'lib/postcl/store.rb', line 61 def package(, postcode) filter(proc { |p| p[:barcode].upcase == .upcase && p[:postcode].upcase == postcode.upcase })[0] end |
#packages ⇒ Object
49 50 51 |
# File 'lib/postcl/store.rb', line 49 def packages @data[:packages] end |
#postcode ⇒ Object
40 41 42 |
# File 'lib/postcl/store.rb', line 40 def postcode @data[:postcode] end |
#postcode=(postcode) ⇒ Object
44 45 46 47 |
# File 'lib/postcl/store.rb', line 44 def postcode=(postcode) @data[:postcode] = postcode save end |
#prompt_add(resp) ⇒ Object
69 70 71 72 73 |
# File 'lib/postcl/store.rb', line 69 def prompt_add(resp) if TTY::Prompt.new.yes?("Het lijkt er op dat deze zending nog niet is opgeslagen, wilt u hem toevoegen?") add(resp) end end |
#promt_list ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/postcl/store.rb', line 75 def promt_list p_list = @args["--alles"] ? packages : undelivered @session.error_exit("Geen zendingen in huidige selectie.") unless p_list.size > 0 choices = [] p_list.each_with_index do |p, i| choices << {name: "#{p[:barcode]}, #{p[:postcode]}", value: i} end input = @prompt.multi_select("Selecteer een of meerdere zendingen:", choices) input.each do |i| @args["<barcode>"] << p_list[i][:barcode] @args["<postcode>"] << p_list[i][:postcode] end end |
#undelivered ⇒ Object
57 58 59 |
# File 'lib/postcl/store.rb', line 57 def undelivered filter(proc { |p| p[:undelivered] }) end |