Class: FlatKit::Input::File

Inherits:
FlatKit::Input show all
Defined in:
lib/flat_kit/input/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FlatKit::Input

from

Methods included from DescendantTracker

#children, #find_child, #inherited

Constructor Details

#initialize(obj) ⇒ File

Returns a new instance of File.

Raises:



19
20
21
22
23
24
# File 'lib/flat_kit/input/file.rb', line 19

def initialize(obj)
  @count = 0
  @path = Pathname.new(obj)
  raise FlatKit::Error, "Input #{obj} is not readable" unless @path.readable?
  @io = open_input(path)
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



7
8
9
# File 'lib/flat_kit/input/file.rb', line 7

def count
  @count
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/flat_kit/input/file.rb', line 6

def path
  @path
end

Class Method Details

.handles?(obj) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
# File 'lib/flat_kit/input/file.rb', line 9

def self.handles?(obj)
  return true if obj.instance_of?(Pathname)
  return false unless obj.instance_of?(String)

  # incase these get loaded in different orders
  return false if ::FlatKit::Input::IO.is_stdin?(obj)

  return true
end

Instance Method Details

#closeObject



30
31
32
# File 'lib/flat_kit/input/file.rb', line 30

def close
  @io.close
end

#ioObject



34
35
36
# File 'lib/flat_kit/input/file.rb', line 34

def io
  @io
end

#nameObject



26
27
28
# File 'lib/flat_kit/input/file.rb', line 26

def name
  path.to_s
end