Class: RipperTags::DataReader
- Inherits:
-
Object
- Object
- RipperTags::DataReader
- Defined in:
- lib/ripper-tags/data_reader.rb
Constant Summary collapse
- READ_MODE =
'r:utf-8'
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #debug_dump(obj) ⇒ Object
- #each_tag ⇒ Object
- #file_finder ⇒ Object
-
#initialize(options) ⇒ DataReader
constructor
A new instance of DataReader.
- #normalize_encoding(str) ⇒ Object
- #parse_file(contents, filename) ⇒ Object
- #read_file(filename) ⇒ Object
- #tag_extractor(file) ⇒ Object
Constructor Details
#initialize(options) ⇒ DataReader
108 109 110 |
# File 'lib/ripper-tags/data_reader.rb', line 108 def initialize() @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
104 105 106 |
# File 'lib/ripper-tags/data_reader.rb', line 104 def @options end |
Instance Method Details
#debug_dump(obj) ⇒ Object
151 152 153 |
# File 'lib/ripper-tags/data_reader.rb', line 151 def debug_dump(obj) pp(obj, $stderr) end |
#each_tag ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/ripper-tags/data_reader.rb', line 131 def each_tag return to_enum(__method__) unless block_given? file_finder.each_file do |file| begin $stderr.puts "Parsing file #{file}" if .verbose extractor = tag_extractor(file) rescue => err if .force $stderr.puts "Error parsing `#{file}': #{err.}" else raise err end else extractor..each do |tag| yield tag end end end end |
#file_finder ⇒ Object
112 113 114 |
# File 'lib/ripper-tags/data_reader.rb', line 112 def file_finder FileFinder.new() end |
#normalize_encoding(str) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/ripper-tags/data_reader.rb', line 121 def normalize_encoding(str) if str.respond_to?(:encode!) # strip invalid byte sequences str.encode!('utf-16', :invalid => :replace, :undef => :replace) str.encode!('utf-8') else str end end |
#parse_file(contents, filename) ⇒ Object
155 156 157 158 159 |
# File 'lib/ripper-tags/data_reader.rb', line 155 def parse_file(contents, filename) sexp = Parser.new(contents, filename).parse debug_dump(sexp) if .debug sexp end |
#read_file(filename) ⇒ Object
116 117 118 119 |
# File 'lib/ripper-tags/data_reader.rb', line 116 def read_file(filename) str = File.open(filename, READ_MODE) {|f| f.read } normalize_encoding(str) end |