Class: Locabulary::JsonCreator
- Inherits:
-
Object
- Object
- Locabulary::JsonCreator
- Defined in:
- lib/locabulary/json_creator.rb
Overview
Responsible for capturing predicate_name from a given source and writing it to a file
Defined Under Namespace
Modules: GoogleAccessTokenFetcher Classes: GoogleSpreadsheet
Instance Attribute Summary collapse
-
#data_fetcher ⇒ Object
readonly
Returns the value of attribute data_fetcher.
-
#document_key ⇒ Object
readonly
Returns the value of attribute document_key.
-
#json_data ⇒ Object
readonly
Returns the value of attribute json_data.
-
#output_filepath ⇒ Object
Returns the value of attribute output_filepath.
-
#predicate_name ⇒ Object
readonly
Returns the value of attribute predicate_name.
-
#spreadsheet_data ⇒ Object
readonly
Returns the value of attribute spreadsheet_data.
Instance Method Summary collapse
- #create_or_update ⇒ Object
-
#initialize(document_key, predicate_name, data_fetcher = default_data_fetcher) ⇒ JsonCreator
constructor
A new instance of JsonCreator.
-
#write_to_file ⇒ Object
:nocov:.
Constructor Details
#initialize(document_key, predicate_name, data_fetcher = default_data_fetcher) ⇒ JsonCreator
Returns a new instance of JsonCreator.
10 11 12 13 14 15 |
# File 'lib/locabulary/json_creator.rb', line 10 def initialize(document_key, predicate_name, data_fetcher = default_data_fetcher) @document_key = document_key @predicate_name = predicate_name @output_filepath = Utility.filename_for_predicate_name(predicate_name) @data_fetcher = data_fetcher end |
Instance Attribute Details
#data_fetcher ⇒ Object (readonly)
Returns the value of attribute data_fetcher.
17 18 19 |
# File 'lib/locabulary/json_creator.rb', line 17 def data_fetcher @data_fetcher end |
#document_key ⇒ Object (readonly)
Returns the value of attribute document_key.
17 18 19 |
# File 'lib/locabulary/json_creator.rb', line 17 def document_key @document_key end |
#json_data ⇒ Object (readonly)
Returns the value of attribute json_data.
17 18 19 |
# File 'lib/locabulary/json_creator.rb', line 17 def json_data @json_data end |
#output_filepath ⇒ Object
Returns the value of attribute output_filepath.
18 19 20 |
# File 'lib/locabulary/json_creator.rb', line 18 def output_filepath @output_filepath end |
#predicate_name ⇒ Object (readonly)
Returns the value of attribute predicate_name.
17 18 19 |
# File 'lib/locabulary/json_creator.rb', line 17 def predicate_name @predicate_name end |
#spreadsheet_data ⇒ Object (readonly)
Returns the value of attribute spreadsheet_data.
17 18 19 |
# File 'lib/locabulary/json_creator.rb', line 17 def spreadsheet_data @spreadsheet_data end |
Instance Method Details
#create_or_update ⇒ Object
20 21 22 23 24 |
# File 'lib/locabulary/json_creator.rb', line 20 def create_or_update rows = data_fetcher.call(document_key) data = extract_data_from(rows) convert_to_json(data) end |
#write_to_file ⇒ Object
:nocov:
27 28 29 30 31 |
# File 'lib/locabulary/json_creator.rb', line 27 def write_to_file File.open(output_filepath, "w") do |f| f.puts json_data end end |