Class: I18nDefScanner::Scanning

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_def_scanner/scanning.rb

Constant Summary collapse

DEFAULT_LOAD_PATH =
'config/locales/**/*.yml'
NOT_FOUND_MESSAGE =
'yml key not found'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(load_path: DEFAULT_LOAD_PATH, query_path:) ⇒ Scanning

Returns a new instance of Scanning.



10
11
12
13
# File 'lib/i18n_def_scanner/scanning.rb', line 10

def initialize(load_path: DEFAULT_LOAD_PATH, query_path:)
  self.load_path = load_path
  self.query_path = query_path
end

Instance Attribute Details

#load_pathObject

Returns the value of attribute load_path.



8
9
10
# File 'lib/i18n_def_scanner/scanning.rb', line 8

def load_path
  @load_path
end

#query_pathObject

Returns the value of attribute query_path.



8
9
10
# File 'lib/i18n_def_scanner/scanning.rb', line 8

def query_path
  @query_path
end

Instance Method Details

#resultObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/i18n_def_scanner/scanning.rb', line 15

def result
  definition = nil

  files.each do |file_path|
    document_hash = I18nDefScanner::YAML.load_file(file_path)
    string_number = document_hash.dig(*query_keys)
    definition = "#{file_path}:#{string_number}" if string_number
  end

  definition || NOT_FOUND_MESSAGE
end