Class: Nasdaq::CommandLine
- Inherits:
-
SuperDocopt::Base
- Object
- SuperDocopt::Base
- Nasdaq::CommandLine
- Defined in:
- lib/nasdaq/command_line.rb
Overview
Handles the command line interface
Instance Attribute Summary collapse
-
#csv ⇒ Object
readonly
Returns the value of attribute csv.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #before_execute ⇒ Object
- #get ⇒ Object
- #nasdaq ⇒ Object
- #pretty ⇒ Object
- #save ⇒ Object
- #see ⇒ Object
- #url ⇒ Object
Instance Attribute Details
#csv ⇒ Object (readonly)
Returns the value of attribute csv.
12 13 14 |
# File 'lib/nasdaq/command_line.rb', line 12 def csv @csv end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
12 13 14 |
# File 'lib/nasdaq/command_line.rb', line 12 def file @file end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
12 13 14 |
# File 'lib/nasdaq/command_line.rb', line 12 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/nasdaq/command_line.rb', line 12 def path @path end |
Instance Method Details
#before_execute ⇒ Object
14 15 16 17 18 19 |
# File 'lib/nasdaq/command_line.rb', line 14 def before_execute @path = args['PATH'] @params = translate_params args['PARAMS'] @file = args['FILE'] @csv = args['--csv'] end |
#get ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/nasdaq/command_line.rb', line 21 def get if csv puts nasdaq.get_csv path, params else payload = nasdaq.get! path, params puts payload.response.body end end |
#nasdaq ⇒ Object
52 53 54 |
# File 'lib/nasdaq/command_line.rb', line 52 def nasdaq @nasdaq ||= nasdaq! end |
#pretty ⇒ Object
39 40 41 42 |
# File 'lib/nasdaq/command_line.rb', line 39 def pretty payload = nasdaq.get path, params puts JSON.pretty_generate payload end |
#save ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/nasdaq/command_line.rb', line 30 def save success = if csv nasdaq.save_csv file, path, params else nasdaq.save file, path, params end puts success ? "Saved #{file}" : 'Saving failed' end |
#see ⇒ Object
44 45 46 |
# File 'lib/nasdaq/command_line.rb', line 44 def see lp nasdaq.get path, params end |
#url ⇒ Object
48 49 50 |
# File 'lib/nasdaq/command_line.rb', line 48 def url puts nasdaq.url path, params end |