Class: Cldr::Export::Yaml

Inherits:
Ya2YAML
  • Object
show all
Defined in:
lib/cldr/export/yaml.rb

Instance Method Summary collapse

Constructor Details

#initializeYaml

Returns a new instance of Yaml.



6
7
8
# File 'lib/cldr/export/yaml.rb', line 6

def initialize
  super(:syck_compatible => true)
end

Instance Method Details

#emit(object, level = 1) ⇒ Object



26
27
28
29
# File 'lib/cldr/export/yaml.rb', line 26

def emit(object, level = 1)
	result = object.is_a?(Symbol) ? object.inspect : super
	result.gsub(/(\s{1})(no):/i) { %(#{$1}"#{$2}":) } # FIXME fucking spaghetti code
end

#export(locale, component, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cldr/export/yaml.rb', line 10

def export(locale, component, options = {})
  data = Export.data(component, locale, options)
  unless data.empty?
    data = data.deep_stringify_keys if data.respond_to?(:deep_stringify_keys)
    data = { locale.to_s.gsub('_', '-') => data } if locale != ""
    path = Export.path(locale, component, 'yml')
    Export.write(path, yaml(data))
    yield(component, locale, path) if block_given?
    data
  end
end

#is_one_plain_line?(str) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
# File 'lib/cldr/export/yaml.rb', line 31

def is_one_plain_line?(str)
	# removed REX_BOOL, REX_INT
	str !~ /^([\-\?:,\[\]\{\}\#&\*!\|>'"%@`\s]|---|\.\.\.)/    &&
	str !~ /[:\#\s\[\]\{\},]/                                  &&
	str !~ /#{REX_ANY_LB}/                                     &&
	str !~ /^(#{REX_FLOAT}|#{REX_MERGE}|#{REX_NULL}|#{REX_TIMESTAMP}|#{REX_VALUE})$/x
end

#yaml(data) ⇒ Object



22
23
24
# File 'lib/cldr/export/yaml.rb', line 22

def yaml(data)
	emit(data, 1)[1..-1]
end