Class: FlatKit::Input::File

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

Overview

Internal: Handler for file based input

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, #find_children, #inherited

Constructor Details

#initialize(obj) ⇒ File

Returns a new instance of File.

Raises:



23
24
25
26
27
28
29
30
# File 'lib/flat_kit/input/file.rb', line 23

def initialize(obj)
  super()
  @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.



11
12
13
# File 'lib/flat_kit/input/file.rb', line 11

def count
  @count
end

#ioObject (readonly)

Returns the value of attribute io.



11
12
13
# File 'lib/flat_kit/input/file.rb', line 11

def io
  @io
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/flat_kit/input/file.rb', line 11

def path
  @path
end

Class Method Details

.handles?(obj) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
# File 'lib/flat_kit/input/file.rb', line 13

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.stdin?(obj)

  true
end

Instance Method Details

#closeObject



36
37
38
# File 'lib/flat_kit/input/file.rb', line 36

def close
  @io.close
end

#nameObject



32
33
34
# File 'lib/flat_kit/input/file.rb', line 32

def name
  path.to_s
end