Class: Gigbot::Source
- Inherits:
-
Object
- Object
- Gigbot::Source
- Defined in:
- lib/gigbot/source.rb
Constant Summary collapse
- SOURCES_YAML =
File.dirname(__FILE__) + '/sources.yml'
Instance Attribute Summary collapse
-
#imported ⇒ Object
readonly
Returns the value of attribute imported.
-
#parser_name ⇒ Object
readonly
Returns the value of attribute parser_name.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #id ⇒ Object
- #import ⇒ Object
- #import_deep(gig) ⇒ Object
-
#initialize(url, parser_name, title) ⇒ Source
constructor
A new instance of Source.
- #parser ⇒ Object
- #parser_class ⇒ Object
Constructor Details
#initialize(url, parser_name, title) ⇒ Source
Returns a new instance of Source.
12 13 14 15 16 17 |
# File 'lib/gigbot/source.rb', line 12 def initialize(url, parser_name, title) @url = url @parser_name = parser_name @title = title @imported = [] end |
Instance Attribute Details
#imported ⇒ Object (readonly)
Returns the value of attribute imported.
10 11 12 |
# File 'lib/gigbot/source.rb', line 10 def imported @imported end |
#parser_name ⇒ Object (readonly)
Returns the value of attribute parser_name.
10 11 12 |
# File 'lib/gigbot/source.rb', line 10 def parser_name @parser_name end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
10 11 12 |
# File 'lib/gigbot/source.rb', line 10 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/gigbot/source.rb', line 10 def url @url end |
Class Method Details
.all ⇒ Object
49 50 51 52 53 54 |
# File 'lib/gigbot/source.rb', line 49 def self.all definitions = YAML.load_file(SOURCES_YAML) definitions.map do |definition| new(definition['url'], definition['parser'], definition['title']) end end |
.each ⇒ Object
56 57 58 59 60 |
# File 'lib/gigbot/source.rb', line 56 def self.each all.each do |source| yield source end end |
.find(id) ⇒ Object
62 63 64 |
# File 'lib/gigbot/source.rb', line 62 def self.find(id) all.find {|source| source.id == id} end |
Instance Method Details
#id ⇒ Object
27 28 29 |
# File 'lib/gigbot/source.rb', line 27 def id Digest::SHA1.hexdigest(url) end |
#import ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/gigbot/source.rb', line 31 def import @imported = [] parser.parse do |params| gig = Gig.new(params.merge(source_id: self.id)) gig.save @imported << gig end end |
#import_deep(gig) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/gigbot/source.rb', line 40 def import_deep(gig) params = parser.parse_deep(gig) if params.length > 0 return gig.update_attributes(params) else return false end end |
#parser ⇒ Object
23 24 25 |
# File 'lib/gigbot/source.rb', line 23 def parser @parser ||= parser_class.new(url) end |
#parser_class ⇒ Object
19 20 21 |
# File 'lib/gigbot/source.rb', line 19 def parser_class Gigbot::Parsers[parser_name] end |