Class: PhraseAppUpdater::LocaleFile

Inherits:
Object
  • Object
show all
Defined in:
lib/phraseapp_updater/locale_file.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, YAMLFile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#locale_nameObject (readonly)

Returns the value of attribute locale_name.



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

def locale_name
  @locale_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



36
37
38
39
40
41
42
43
44
45
# File 'lib/phraseapp_updater/locale_file.rb', line 36

def 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

.dump(_hash) ⇒ Object

Raises:

  • (RuntimeError)


59
60
61
# File 'lib/phraseapp_updater/locale_file.rb', line 59

def dump(_hash)
  raise RuntimeError.new("Abstract method")
end

.extensionObject

Raises:

  • (RuntimeError)


47
48
49
# File 'lib/phraseapp_updater/locale_file.rb', line 47

def extension
  raise RuntimeError.new("Abstract method")
end

.from_file_content(locale_name, content) ⇒ Object



15
16
17
# File 'lib/phraseapp_updater/locale_file.rb', line 15

def from_file_content(locale_name, content)
  new(locale_name, load(content))
end

.from_hash(locale_name, hash) ⇒ Object



11
12
13
# File 'lib/phraseapp_updater/locale_file.rb', line 11

def from_hash(locale_name, hash)
  new(locale_name, hash)
end

.load(_content) ⇒ Object

Raises:

  • (RuntimeError)


55
56
57
# File 'lib/phraseapp_updater/locale_file.rb', line 55

def load(_content)
  raise RuntimeError.new("Abstract method")
end

.load_directory(directory) ⇒ Object



19
20
21
22
23
# File 'lib/phraseapp_updater/locale_file.rb', line 19

def load_directory(directory)
  Dir[File.join(directory, "*.#{extension}")].map do |filename|
    load_file(filename)
  end
end

.load_file(filename) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/phraseapp_updater/locale_file.rb', line 25

def load_file(filename)
  unless File.readable?(filename) && File.file?(filename)
    raise RuntimeError.new("Couldn't read localization file at #{filename}")
  end

  locale_name = File.basename(filename).chomp(".#{extension}")
  from_file_content(locale_name, File.read(filename))
end

.phraseapp_typeObject

Raises:

  • (RuntimeError)


51
52
53
# File 'lib/phraseapp_updater/locale_file.rb', line 51

def phraseapp_type
  raise RuntimeError.new("Abstract method")
end

Instance Method Details

#filenameObject



68
69
70
# File 'lib/phraseapp_updater/locale_file.rb', line 68

def filename
  "#{locale_name}.#{self.class.extension}"
end

#to_sObject



64
65
66
# File 'lib/phraseapp_updater/locale_file.rb', line 64

def to_s
  locale_name
end