Class: Lokale::LFile
- Inherits:
-
Object
- Object
- Lokale::LFile
- Defined in:
- lib/lokale/agent.rb,
lib/lokale/model.rb
Instance Attribute Summary collapse
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #content ⇒ Object
- #full_name ⇒ Object
-
#initialize(file_path) ⇒ LFile
constructor
A new instance of LFile.
- #inspect ⇒ Object
- #keys ⇒ Object
- #parsed ⇒ Object
- #repeats ⇒ Object
- #strings_file? ⇒ Boolean
- #write(content) ⇒ Object
Constructor Details
#initialize(file_path) ⇒ LFile
Returns a new instance of LFile.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/lokale/model.rb', line 24 def initialize(file_path) @path = file_path File.basename(file_path) =~ /^(.+)\.([^\.]*?)$/ @name = $1 @type = $2 file_path =~ /\/(.{1,8})\.lproj\// @lang = $1 end |
Instance Attribute Details
#lang ⇒ Object (readonly)
Returns the value of attribute lang.
23 24 25 |
# File 'lib/lokale/model.rb', line 23 def lang @lang end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/lokale/model.rb', line 23 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
23 24 25 |
# File 'lib/lokale/model.rb', line 23 def path @path end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
23 24 25 |
# File 'lib/lokale/model.rb', line 23 def type @type end |
Class Method Details
.localization_file?(path) ⇒ Boolean
35 36 37 38 39 40 |
# File 'lib/lokale/model.rb', line 35 def self.localization_file?(path) File.directory?(path) == false && (path =~ /\/Pods\//) == nil && (path =~ /\.bundle\//) == nil && (path =~ /\/(.{1,8})\.lproj\//) end |
Instance Method Details
#content ⇒ Object
59 60 61 |
# File 'lib/lokale/model.rb', line 59 def content File.read(@path) end |
#full_name ⇒ Object
51 52 53 |
# File 'lib/lokale/model.rb', line 51 def full_name "#{@name}.#{@type}" end |
#inspect ⇒ Object
47 48 49 |
# File 'lib/lokale/model.rb', line 47 def inspect "<LF:#{@lang}/#{full_name}>" end |
#keys ⇒ Object
50 51 52 53 |
# File 'lib/lokale/agent.rb', line 50 def keys return nil if parsed.nil? parsed.map(&:key) end |
#parsed ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/lokale/model.rb', line 67 def parsed return @parsed unless @parsed.nil? @parsed = case type when "strings" then LString.strings_from_file(@path, @lang) when "stringsdict" then [] else nil end end |
#repeats ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lokale/agent.rb', line 38 def repeats return [] if @parsed.nil? uniq_keys = keys.to_set keys.delete_if do |k| if uniq_keys.include? k uniq_keys.delete k true end end end |
#strings_file? ⇒ Boolean
55 56 57 |
# File 'lib/lokale/model.rb', line 55 def strings_file? @type == "strings" || @type == "stringsdict" end |
#write(content) ⇒ Object
63 64 65 |
# File 'lib/lokale/model.rb', line 63 def write(content) File.write(@path, content) end |