Class: Lokale::LFile

Inherits:
Object
  • Object
show all
Defined in:
lib/lokale/agent.rb,
lib/lokale/model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ LFile

Returns a new instance of LFile.



38
39
40
41
42
43
44
45
46
47
# File 'lib/lokale/model.rb', line 38

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

#langObject (readonly)

Returns the value of attribute lang.



37
38
39
# File 'lib/lokale/model.rb', line 37

def lang
  @lang
end

#nameObject (readonly)

Returns the value of attribute name.



37
38
39
# File 'lib/lokale/model.rb', line 37

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



37
38
39
# File 'lib/lokale/model.rb', line 37

def path
  @path
end

#typeObject (readonly)

Returns the value of attribute type.



37
38
39
# File 'lib/lokale/model.rb', line 37

def type
  @type
end

Class Method Details

.try_to_read(file_path) ⇒ Object



49
50
51
52
# File 'lib/lokale/model.rb', line 49

def self.try_to_read(file_path)
  return nil unless file_path.localization_file?
  LFile.new(file_path)
end

Instance Method Details

#contentObject



66
67
68
# File 'lib/lokale/model.rb', line 66

def content
	File.read(@path)
end

#full_nameObject



58
59
60
# File 'lib/lokale/model.rb', line 58

def full_name
  "#{@name}.#{@type}"
end

#inspectObject



54
55
56
# File 'lib/lokale/model.rb', line 54

def inspect 
  "<LF:#{@lang}/#{full_name}>"
end

#keysObject



24
25
26
27
# File 'lib/lokale/agent.rb', line 24

def keys 
  return nil if parsed.nil?
  parsed.map(&:key)
end

#parsedObject



74
75
76
77
78
79
80
81
# File 'lib/lokale/model.rb', line 74

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

#repeatsObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lokale/agent.rb', line 12

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

Returns:

  • (Boolean)


62
63
64
# File 'lib/lokale/model.rb', line 62

def strings_file?
  @type == "strings" || @type == "stringsdict"
end

#write(content) ⇒ Object



70
71
72
# File 'lib/lokale/model.rb', line 70

def write(content)
	File.write(@path, content)
end