Class: Yamlook::File
- Inherits:
-
Object
- Object
- Yamlook::File
- Defined in:
- lib/yamlook/file.rb
Overview
Yaml file to perform search
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
-
#initialize(filename) ⇒ File
constructor
A new instance of File.
- #search(keys) ⇒ Object
Constructor Details
#initialize(filename) ⇒ File
Returns a new instance of File.
8 9 10 |
# File 'lib/yamlook/file.rb', line 8 def initialize(filename) @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/yamlook/file.rb', line 6 def filename @filename end |
Instance Method Details
#search(keys) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/yamlook/file.rb', line 12 def search(keys) file = ::File.read(filename) handler = Handler.new(keys: keys, locales: LOCALES) parser = ::Psych::Parser.new(handler) findings = parser.parse(file).handler.found.map do |value, line, column| "#{filename}:#{line}:#{column}\n#{value}" end findings if findings.any? rescue ::Psych::Exception nil end |