Class: Aozora2Html::YamlLoader
- Inherits:
-
Object
- Object
- Aozora2Html::YamlLoader
- Defined in:
- lib/aozora2html/yaml_loader.rb
Overview
YAML Loader class for Shift_JIS
Instance Method Summary collapse
-
#initialize(base_dir) ⇒ YamlLoader
constructor
A new instance of YamlLoader.
- #load(path) ⇒ Object
- #normalize_data(data) ⇒ Object
Constructor Details
#initialize(base_dir) ⇒ YamlLoader
Returns a new instance of YamlLoader.
8 9 10 |
# File 'lib/aozora2html/yaml_loader.rb', line 8 def initialize(base_dir) @base_dir = base_dir end |
Instance Method Details
#load(path) ⇒ Object
12 13 14 15 |
# File 'lib/aozora2html/yaml_loader.rb', line 12 def load(path) tmp_data = YAML.load_file(File.join(@base_dir, path)) normalize_data(tmp_data) end |
#normalize_data(data) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/aozora2html/yaml_loader.rb', line 19 def normalize_data(data) case data when String data.to_sjis when Hash new_data = {} data.each do |k, v| new_data[normalize_data(k)] = normalize_data(v) end new_data when Array data.map { |item| normalize_data(item) } else # noop data end end |