Class: Uktt::CLI
- Inherits:
-
Thor
- Object
- Thor
- Uktt::CLI
- Defined in:
- lib/uktt/cli.rb
Overview
Implemets a CLI using Thor
Instance Method Summary collapse
- #chapter(chapter_id) ⇒ Object
- #chapters ⇒ Object
- #commodity(commodity_id) ⇒ Object
- #heading(heading_id) ⇒ Object
- #info ⇒ Object
- #monetary_exchange_rates ⇒ Object
- #pdf(chapter_id) ⇒ Object
- #section(section_id) ⇒ Object
- #sections ⇒ Object
- #test ⇒ Object
Instance Method Details
#chapter(chapter_id) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/uktt/cli.rb', line 65 def chapter(chapter_id) if [:goods] && [:version] != 'v2' puts 'V2 is required. Use `-a v2`' return end uktt = Uktt::Chapter.new(.merge(host: host, chapter_id: chapter_id)) puts uktt.send(action) end |
#chapters ⇒ Object
76 77 78 |
# File 'lib/uktt/cli.rb', line 76 def chapters puts Uktt::Chapter.new(.merge(host: host)).retrieve_all end |
#commodity(commodity_id) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/uktt/cli.rb', line 95 def commodity(commodity_id) if [:goods] || [:note] puts 'Option not supported for this object' return end puts Uktt::Commodity.new(.merge(host: host, commodity_id: commodity_id)).send(action) end |
#heading(heading_id) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/uktt/cli.rb', line 81 def heading(heading_id) if [:goods] && [:version] != 'v2' puts 'V2 is required. Use `-a v2`' return elsif [:note] puts 'Option not supported for this object' return end uktt = Uktt::Heading.new(.merge(host: host, heading_id: heading_id)) puts uktt.send(action) end |
#info ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/uktt/cli.rb', line 130 def info if [:version] puts Uktt::VERSION elsif ARGV help else help end end |
#monetary_exchange_rates ⇒ Object
105 106 107 |
# File 'lib/uktt/cli.rb', line 105 def monetary_exchange_rates puts Uktt::MonetaryExchangeRate.new(.merge(host: host)).retrieve_all end |
#pdf(chapter_id) ⇒ Object
114 115 116 117 118 |
# File 'lib/uktt/cli.rb', line 114 def pdf(chapter_id) puts "Making a PDF for Chapter #{chapter_id}" start_time = Time.now puts "Finished #{Uktt::Pdf.new(.merge(chapter_id: chapter_id)).make_chapter} in #{Time.now - start_time}" end |
#section(section_id) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/uktt/cli.rb', line 46 def section(section_id) if [:goods] && [:version] != 'v2' puts 'V2 is required. Use `-a v2`' return elsif [:changes] puts 'Option not supported for this object' return end uktt = Uktt::Section.new(.merge(host: host, section_id: section_id)) puts uktt.send(action) end |
#sections ⇒ Object
60 61 62 |
# File 'lib/uktt/cli.rb', line 60 def sections puts Uktt::Section.new(.merge(host: host)).retrieve_all end |
#test ⇒ Object
121 122 123 124 125 126 |
# File 'lib/uktt/cli.rb', line 121 def test host, version, _json, _debug, _filepath = () ver = version ? "VER=#{version} " : '' prod = host == API_HOST_PROD ? 'PROD=true ' : '' puts `#{ver}#{prod}bundle exec rspec ./spec/uktt_api_spec.rb` end |