Class: Lokale::LFile
- Inherits:
-
Object
- Object
- Lokale::LFile
- Defined in:
- lib/lokale.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
- #full_name ⇒ Object
-
#initialize(file_path) ⇒ LFile
constructor
A new instance of LFile.
- #inspect ⇒ Object
- #keys ⇒ Object
- #parsed ⇒ Object
- #repeats ⇒ Object
- #strings_file? ⇒ Boolean
Constructor Details
#initialize(file_path) ⇒ LFile
Returns a new instance of LFile.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lokale.rb', line 45 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.
44 45 46 |
# File 'lib/lokale.rb', line 44 def lang @lang end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
44 45 46 |
# File 'lib/lokale.rb', line 44 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
44 45 46 |
# File 'lib/lokale.rb', line 44 def path @path end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
44 45 46 |
# File 'lib/lokale.rb', line 44 def type @type end |
Class Method Details
.try_to_read(file_path) ⇒ Object
56 57 58 59 |
# File 'lib/lokale.rb', line 56 def self.try_to_read(file_path) return nil unless file_path.localization_file? LFile.new(file_path) end |
Instance Method Details
#full_name ⇒ Object
65 66 67 |
# File 'lib/lokale.rb', line 65 def full_name "#{@name}.#{@type}" end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/lokale.rb', line 61 def inspect "<#{@lang}/#{full_name}>" end |
#keys ⇒ Object
91 92 93 94 |
# File 'lib/lokale.rb', line 91 def keys return nil if parsed.nil? parsed.map(&:key) end |
#parsed ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/lokale.rb', line 69 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
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/lokale.rb', line 78 def repeats return [] if @parsed.nil? keys = @parsed.map(&:key) 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
97 98 99 |
# File 'lib/lokale.rb', line 97 def strings_file? @type == "strings" || @type == "stringsdict" end |