Class: PhraseAppUpdater::LocaleFile
- Inherits:
-
Object
- Object
- PhraseAppUpdater::LocaleFile
- Defined in:
- lib/phraseapp_updater/locale_file.rb,
lib/phraseapp_updater/locale_file/loader.rb,
lib/phraseapp_updater/locale_file/json_file.rb,
lib/phraseapp_updater/locale_file/yaml_file.rb
Defined Under Namespace
Classes: BadFileTypeError, JSONFile, Loader, YAMLFile
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parsed_content ⇒ Object
readonly
Returns the value of attribute parsed_content.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, content) ⇒ LocaleFile
constructor
Expects a Ruby hash.
- #name_with_extension ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, content) ⇒ LocaleFile
Expects a Ruby hash
26 27 28 29 30 31 |
# File 'lib/phraseapp_updater/locale_file.rb', line 26 def initialize(name, content) @name = name @content = content @parsed_content = parse(@content) format_content! end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
6 7 8 |
# File 'lib/phraseapp_updater/locale_file.rb', line 6 def content @content end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/phraseapp_updater/locale_file.rb', line 6 def name @name end |
#parsed_content ⇒ Object (readonly)
Returns the value of attribute parsed_content.
6 7 8 |
# File 'lib/phraseapp_updater/locale_file.rb', line 6 def parsed_content @parsed_content end |
Class Method Details
.class_for_file_format(type) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/phraseapp_updater/locale_file.rb', line 14 def self.class_for_file_format(type) case type.downcase when "json" JSONFile when "yml", "yaml" YAMLFile else raise BadFileTypeError.new("Invalid file type: #{type}") end end |
.from_hash(name, hash) ⇒ Object
10 11 12 |
# File 'lib/phraseapp_updater/locale_file.rb', line 10 def self.from_hash(name, hash) raise RuntimeError.new("Must be implemented in a subclass.") end |
Instance Method Details
#name_with_extension ⇒ Object
37 38 39 |
# File 'lib/phraseapp_updater/locale_file.rb', line 37 def name_with_extension "#{name}.#{self.class::EXTENSION}" end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/phraseapp_updater/locale_file.rb', line 33 def to_s "#{name}, #{content[0,20]}..." end |