Module: I18nDefScanner::YAML

Defined in:
lib/i18n_def_scanner/yaml.rb

Defined Under Namespace

Modules: Handlers, Nodes, Visitors

Class Method Summary collapse

Class Method Details

.load(yaml, filename: nil) ⇒ Object



13
14
15
16
17
# File 'lib/i18n_def_scanner/yaml.rb', line 13

def self.load(yaml, filename: nil)
  result = parse(yaml, filename: filename)
  result = result.to_ruby if result
  result
end

.load_file(filename) ⇒ Object



7
8
9
10
11
# File 'lib/i18n_def_scanner/yaml.rb', line 7

def self.load_file(filename)
  File.open(filename, 'r:bom|utf-8') do |f|
    load(f, filename: filename)
  end
end

.parse(yaml, filename: nil) ⇒ Object



19
20
21
22
23
# File 'lib/i18n_def_scanner/yaml.rb', line 19

def self.parse(yaml, filename: nil)
  parse_stream(yaml, filename: filename) do |node|
    return node
  end
end

.parse_stream(yaml, filename: nil, &block) ⇒ Object



25
26
27
28
29
# File 'lib/i18n_def_scanner/yaml.rb', line 25

def self.parse_stream(yaml, filename: nil, &block)
  handler = YAML::Handlers::DocumentStream.new(&block)
  parser = Psych::Parser.new(handler)
  parser.parse(yaml, filename)
end