Class: RemoteTable::File
- Inherits:
-
Object
- Object
- RemoteTable::File
- Defined in:
- lib/remote_table/file.rb
Instance Attribute Summary collapse
-
#crop ⇒ Object
Returns the value of attribute crop.
-
#cut ⇒ Object
Returns the value of attribute cut.
-
#delimiter ⇒ Object
Returns the value of attribute delimiter.
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#format ⇒ Object
Returns the value of attribute format.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#keep_blank_rows ⇒ Object
Returns the value of attribute keep_blank_rows.
-
#path ⇒ Object
Returns the value of attribute path.
-
#schema ⇒ Object
Returns the value of attribute schema.
-
#schema_name ⇒ Object
Returns the value of attribute schema_name.
-
#sheet ⇒ Object
Returns the value of attribute sheet.
-
#skip ⇒ Object
Returns the value of attribute skip.
-
#trap ⇒ Object
Returns the value of attribute trap.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(bus) ⇒ File
constructor
A new instance of File.
- #tabulate(path) ⇒ Object
Constructor Details
#initialize(bus) ⇒ File
Returns a new instance of File.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/remote_table/file.rb', line 8 def initialize(bus) @filename = bus[:filename] @format = bus[:format] || format_from_filename @delimiter = bus[:delimiter] @sheet = bus[:sheet] || 0 @skip = bus[:skip] # rows @keep_blank_rows = bus[:keep_blank_rows] || false @crop = bus[:crop] # rows @cut = bus[:cut] # columns @headers = bus[:headers] @schema = bus[:schema] @schema_name = bus[:schema_name] @trap = bus[:trap] @encoding = bus[:encoding] || 'UTF-8' extend "RemoteTable::#{format.to_s.camelcase}".constantize end |
Instance Attribute Details
#crop ⇒ Object
Returns the value of attribute crop.
3 4 5 |
# File 'lib/remote_table/file.rb', line 3 def crop @crop end |
#cut ⇒ Object
Returns the value of attribute cut.
3 4 5 |
# File 'lib/remote_table/file.rb', line 3 def cut @cut end |
#delimiter ⇒ Object
Returns the value of attribute delimiter.
3 4 5 |
# File 'lib/remote_table/file.rb', line 3 def delimiter @delimiter end |
#encoding ⇒ Object
Returns the value of attribute encoding.
4 5 6 |
# File 'lib/remote_table/file.rb', line 4 def encoding @encoding end |
#filename ⇒ Object
Returns the value of attribute filename.
3 4 5 |
# File 'lib/remote_table/file.rb', line 3 def filename @filename end |
#format ⇒ Object
Returns the value of attribute format.
3 4 5 |
# File 'lib/remote_table/file.rb', line 3 def format @format end |
#headers ⇒ Object
Returns the value of attribute headers.
3 4 5 |
# File 'lib/remote_table/file.rb', line 3 def headers @headers end |
#keep_blank_rows ⇒ Object
Returns the value of attribute keep_blank_rows.
6 7 8 |
# File 'lib/remote_table/file.rb', line 6 def keep_blank_rows @keep_blank_rows end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/remote_table/file.rb', line 5 def path @path end |
#schema ⇒ Object
Returns the value of attribute schema.
3 4 5 |
# File 'lib/remote_table/file.rb', line 3 def schema @schema end |
#schema_name ⇒ Object
Returns the value of attribute schema_name.
3 4 5 |
# File 'lib/remote_table/file.rb', line 3 def schema_name @schema_name end |
#sheet ⇒ Object
Returns the value of attribute sheet.
3 4 5 |
# File 'lib/remote_table/file.rb', line 3 def sheet @sheet end |
#skip ⇒ Object
Returns the value of attribute skip.
3 4 5 |
# File 'lib/remote_table/file.rb', line 3 def skip @skip end |
#trap ⇒ Object
Returns the value of attribute trap.
3 4 5 |
# File 'lib/remote_table/file.rb', line 3 def trap @trap end |
Class Method Details
.convert_to_utf8(str, encoding) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/remote_table/file.rb', line 27 def convert_to_utf8(str, encoding) if encoding == 'UTF-8' str.toutf8 # just in case else @_iconv ||= Hash.new @_iconv[encoding] ||= Iconv.new 'UTF-8', encoding @_iconv[encoding].iconv(str).toutf8 end end |
Instance Method Details
#tabulate(path) ⇒ Object
38 39 40 41 42 |
# File 'lib/remote_table/file.rb', line 38 def tabulate(path) define_fixed_width_schema! if format == :fixed_width and schema.is_a?(Array) # TODO move to generic subclass callback self.path = path self end |