Class: Ss2Json::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/ss2json/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Cli

Create a new converter the options are:

* **:file** Input file.
* **:sheet** Name of the sheet to use.
* **:first_row** Where the title of the columns is.
* **:check_column** Output only the results with a value present on the specific field.
* **:orientation** The data orientation (:horizontal/:vertical).
* **:key_column** Column of the keys for vertical mode.
* **:value_column** Column of the values.
* **:action** Could
  * *:convert* Do the normal conversion.
  * *:list* Will list the sheets.
* **:converter**: Options passed to the converter: Ss2Json::RowConverter


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ss2json/cli.rb', line 34

def initialize(options)
  @options = options
  init_document
  if options[:action] == :list
    @doc.sheets.join("\n")
  else
    if options[:orientation] == :horizontal
      @options[:first_row] += 1
      process_horizontal
    elsif options[:orientation] == :vertical
      process_vertical
    else
      raise "Orientation #{options[:orientation]} not recognized"
    end
  end
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/ss2json/cli.rb', line 7

def content
  @content
end

#docObject (readonly)

Returns the value of attribute doc.



7
8
9
# File 'lib/ss2json/cli.rb', line 7

def doc
  @doc
end

Class Method Details

.startObject

Parse the options from ARGV, initialize the conversion, and return the string with the output



10
11
12
13
14
15
16
17
18
19
# File 'lib/ss2json/cli.rb', line 10

def self.start
  options = Ss2Json::Options.parse!
  converter =  new(options)
  case options[:action]
  when :list
    converter.doc.sheets.join("\n")
  else
    JSON.pretty_generate(converter.content)
  end
end