Class: Yabbie::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/yabbie/source.rb

Instance Method Summary collapse

Constructor Details

#initialize(url_or_file) ⇒ Source

Returns a new instance of Source.



5
6
7
8
# File 'lib/yabbie/source.rb', line 5

def initialize(url_or_file)
  @source = url_or_file
  raise ImproperSourceError.new unless url? || file?
end

Instance Method Details

#file?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/yabbie/source.rb', line 14

def file?
  @source.kind_of?(File)
end

#html?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/yabbie/source.rb', line 18

def html?
  !(url? || file?)
end

#to_sObject



22
23
24
# File 'lib/yabbie/source.rb', line 22

def to_s
  file? ? @source.path : @source
end

#url?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/yabbie/source.rb', line 10

def url?
  @source.is_a?(String) && @source.match(URI::regexp)
end