Module: LoyalSpider::EntityAble::InstanceMethods
- Defined in:
- lib/loyal_spider/ables/entity_able.rb
Instance Method Summary collapse
- #authors ⇒ Object
- #authors_array ⇒ Object
-
#images ⇒ Object
图片.
- #images? ⇒ Boolean
- #initialize(attrs = {}) ⇒ Object
- #tags ⇒ Object
- #tags_array ⇒ Object
- #valid! ⇒ Object
- #valid? ⇒ Boolean
Instance Method Details
#authors ⇒ Object
54 55 56 |
# File 'lib/loyal_spider/ables/entity_able.rb', line 54 def @authors ||= [] end |
#authors_array ⇒ Object
58 59 60 |
# File 'lib/loyal_spider/ables/entity_able.rb', line 58 def @authors_array ||= self..map{|| [:text] } end |
#images ⇒ Object
图片
40 41 42 43 44 45 46 47 48 |
# File 'lib/loyal_spider/ables/entity_able.rb', line 40 def images @images ||= Nokogiri::HTML.parse(self.content).css('img').map do |img_doc| { :src => img_doc.attr('src'), :title => img_doc.attr('title'), :alt => img_doc.attr('alt') } end end |
#images? ⇒ Boolean
50 51 52 |
# File 'lib/loyal_spider/ables/entity_able.rb', line 50 def images? self.images.any? end |
#initialize(attrs = {}) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/loyal_spider/ables/entity_able.rb', line 23 def initialize attrs={} attrs.each do |key, value| self.send(:"#{key}=", value) end self.errors = {} end |
#tags ⇒ Object
31 32 33 |
# File 'lib/loyal_spider/ables/entity_able.rb', line 31 def @tags ||= [] end |
#tags_array ⇒ Object
35 36 37 |
# File 'lib/loyal_spider/ables/entity_able.rb', line 35 def @tags_array ||= self..map{|_tag| _tag[:text] } end |
#valid! ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/loyal_spider/ables/entity_able.rb', line 67 def valid! unless self.content.to_s.strip.size > 0 add_error :content, '不能为空' end unless self.url.to_s.strip.size > 0 add_error :url, '不能为空' end end |
#valid? ⇒ Boolean
62 63 64 65 |
# File 'lib/loyal_spider/ables/entity_able.rb', line 62 def valid? self.valid! self.errors.empty? end |