Class: PhraseAppUpdater::LocaleFile

Inherits:
Object
  • Object
show all
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

Direct Known Subclasses

JSONFile, YAMLFile

Defined Under Namespace

Classes: BadFileTypeError, JSONFile, Loader, YAMLFile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#contentObject (readonly)

Returns the value of attribute content.



6
7
8
# File 'lib/phraseapp_updater/locale_file.rb', line 6

def content
  @content
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/phraseapp_updater/locale_file.rb', line 6

def name
  @name
end

#parsed_contentObject (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

Raises:

  • (RuntimeError)


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_extensionObject



37
38
39
# File 'lib/phraseapp_updater/locale_file.rb', line 37

def name_with_extension
  "#{name}.#{self.class::EXTENSION}"
end

#to_sObject



33
34
35
# File 'lib/phraseapp_updater/locale_file.rb', line 33

def to_s
  "#{name}, #{content[0,20]}..."
end