Class: Locabulary::JsonCreator

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_fetcherObject (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_keyObject (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_dataObject (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_filepathObject

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_nameObject (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_dataObject (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_updateObject



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_fileObject

: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