Class: I18n::Index::File

Inherits:
Object show all
Defined in:
lib/i18n/index/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ File

Returns a new instance of File.



14
15
16
# File 'lib/i18n/index/file.rb', line 14

def initialize(filename)
  self.filename = filename
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



12
13
14
# File 'lib/i18n/index/file.rb', line 12

def filename
  @filename
end

Instance Method Details

#callsObject



35
36
37
# File 'lib/i18n/index/file.rb', line 35

def calls
  @calls ||= ruby.select_translate_calls
end

#rubyObject



26
27
28
29
30
31
32
33
# File 'lib/i18n/index/file.rb', line 26

def ruby
 @ruby ||= begin
   parser.parse
 rescue Ripper::RubyBuilder::ParseError => e
   puts "\nWARNING Ruby 1.9 incompatible syntax in: " + e.message.gsub(Dir.pwd, '') + ". Can not index file."
   Ruby::Program.new(source, filename)
  end
end

#saveObject



44
45
46
# File 'lib/i18n/index/file.rb', line 44

def save
  ::File.open(filename, 'w+') { |f| f.write(source) } # TODO need to modify/write unfiltered source for ERB
end

#sourceObject



18
19
20
21
22
23
24
# File 'lib/i18n/index/file.rb', line 18

def source
 @source ||= begin
   source = ::File.read(filename) # TODO srsly ... how am i supposed to open a file in ruby 1.9?
   source = ::File.open(filename, 'r:iso-8859-1:utf-8') { |f| f.read } unless source.valid_encoding?
   source
  end
end

#update(source) ⇒ Object



39
40
41
42
# File 'lib/i18n/index/file.rb', line 39

def update(source)
  @source = source
  save
end