Class: HistoryReader
- Inherits:
-
Object
- Object
- HistoryReader
- Defined in:
- lib/readers/history_reader.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file_contents ⇒ Object
Returns the value of attribute file_contents.
-
#filename ⇒ Object
Returns the value of attribute filename.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filename) ⇒ HistoryReader
constructor
A new instance of HistoryReader.
- #shell_commands ⇒ Object
- #timestamps? ⇒ Boolean
Constructor Details
#initialize(filename) ⇒ HistoryReader
Returns a new instance of HistoryReader.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/readers/history_reader.rb', line 4 def initialize(filename) @filename = filename path = File.(filename) if File.exist?(path) file = File.open(path, 'r') else raise "File does not exist." + path.inspect end @file_contents = "" if String.method_defined?(:encode) @file_contents = file.read.encode!('UTF-8', 'UTF-8', :invalid => :replace) else ic = Iconv.new('UTF-8', 'UTF-8') file.each do |l| begin @file_contents += ic.iconv(l) + "\n" rescue puts "Encoding error: #{l}" end end end end |
Instance Attribute Details
#file_contents ⇒ Object
Returns the value of attribute file_contents.
2 3 4 |
# File 'lib/readers/history_reader.rb', line 2 def file_contents @file_contents end |
#filename ⇒ Object
Returns the value of attribute filename.
2 3 4 |
# File 'lib/readers/history_reader.rb', line 2 def filename @filename end |
Class Method Details
.files ⇒ Object
43 44 45 |
# File 'lib/readers/history_reader.rb', line 43 def self.files possible_files.map{|f| File.(f) }.select{|f| File.exist?(f) } end |
.timestamps?(filename) ⇒ Boolean
34 35 36 37 |
# File 'lib/readers/history_reader.rb', line 34 def self.(filename) reader = HistoryReader.new(filename) reader. end |
Instance Method Details
#shell_commands ⇒ Object
39 40 41 |
# File 'lib/readers/history_reader.rb', line 39 def shell_commands raw_lines end |
#timestamps? ⇒ Boolean
30 31 32 |
# File 'lib/readers/history_reader.rb', line 30 def (raw_lines.first) end |