class Lokale::LFile

Attributes

lang[R]
name[R]
path[R]
type[R]

Public Class Methods

localization_file?(path) click to toggle source
# 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
new(file_path) click to toggle source
# 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
try_to_read(file_path) click to toggle source
# File lib/lokale/model.rb, line 42
def self.try_to_read(file_path)
  return nil unless localization_file? file_path
  LFile.new(file_path)
end

Public Instance Methods

content() click to toggle source
# File lib/lokale/model.rb, line 59
def content
    File.read(@path)
end
full_name() click to toggle source
# File lib/lokale/model.rb, line 51
def full_name
  "#{@name}.#{@type}"
end
inspect() click to toggle source
# File lib/lokale/model.rb, line 47
def inspect
  "<LF:#{@lang}/#{full_name}>"
end
keys() click to toggle source
# File lib/lokale/agent.rb, line 50
def keys 
  return nil if parsed.nil?
  parsed.map(&:key)
end
parsed() click to toggle source
# 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() click to toggle source
# 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?() click to toggle source
# File lib/lokale/model.rb, line 55
def strings_file?
  @type == "strings" || @type == "stringsdict"
end
write(content) click to toggle source
# File lib/lokale/model.rb, line 63
def write(content)
    File.write(@path, content)
end