Class: Mokuji::Converter

Inherits:
Object
  • Object
show all
Includes:
Validators
Defined in:
lib/mokuji/converter.rb

Overview

{ CONVERTER }

Info

Converts the data from the scanner to JSON or HTML

Output example : String

<html>

...
<body>
 <h1>Icid</h1>
 <h2>19 April 2011 (03:47PM)</h2>
 <nav>
  <a id="expand_all">Expand all directories</a> ---
  <a id="close_all">Close all directories</a>
 </nav>
 <ul id="list"><li class="file">file.txt</li></ul>
</body>
...

</html>

How to use

converter = Mokuji::Converter.new converter_results = converter.convert data_from_scanner

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validators

#json_valid?, #validate_configuration, #validate_data_from_converter, #validate_data_from_scanner, #validate_export_path, #validate_import_path, validate_options

Constructor Details

#initializeConverter

Returns a new instance of Converter.



37
38
39
# File 'lib/mokuji/converter.rb', line 37

def initialize
  validate_configuration
end

Instance Attribute Details

#data_from_scannerObject (readonly)

Returns the value of attribute data_from_scanner.



35
36
37
# File 'lib/mokuji/converter.rb', line 35

def data_from_scanner
  @data_from_scanner
end

#list_nameObject (readonly)

Returns the value of attribute list_name.



35
36
37
# File 'lib/mokuji/converter.rb', line 35

def list_name
  @list_name
end

#output_typeObject (readonly)

Returns the value of attribute output_type.



35
36
37
# File 'lib/mokuji/converter.rb', line 35

def output_type
  @output_type
end

#timeObject (readonly)

Returns the value of attribute time.



35
36
37
# File 'lib/mokuji/converter.rb', line 35

def time
  @time
end

Instance Method Details

#convert(hash) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mokuji/converter.rb', line 41

def convert hash
  validate_data_from_scanner hash
  
  @data_from_scanner = hash
  @output_type = Mokuji::configuration['output_type']
  @list_name = (Mokuji::configuration['list_name'] ||= hash['name'])
  @time = Time.now.strftime('%d %B %Y (%I:%M%p)')
  
  return data = case output_type
    when 'json' then to_json
    when 'html' then to_html
    when 'plain_html' then to_html_plain
    when 'plain_text' then to_plain_text
  end
end