lib/nicoquery/object_mapper/getthumbinfo.rb in nicoquery-0.0.2.4 vs lib/nicoquery/object_mapper/getthumbinfo.rb in nicoquery-0.0.3
- old
+ new
@@ -18,11 +18,11 @@
def title
@hash['title']
end
def description
- @hash['description']
+ @_description ||= Description.new @hash['description']
end
def thumbnail_url
@hash['thumbnail_url']
end
@@ -89,28 +89,58 @@
end
def tags
xml = @xml.scan(/\<tags domain=\"jp\">\n.+\n\<\/tags\>/m)[0]
parsed = Nokogiri::XML xml
- parsed.xpath("//tag").map do |tag_object|
+ parsed.xpath("//tag").map do |tag_object|
generate_tag_hash_by tag_object
end
end
def user_id
@hash['user_id'].to_i
end
+ private
def generate_tag_hash_by(nokogiri_xml)
text = nokogiri_xml.text
lock = if nokogiri_xml.attributes['lock'].present?
nokogiri_xml.attributes['lock'].text.to_i == 1
else
false
end
{ text: text, lock: lock }
+ end
+
+ class Description
+ attr_reader :raw_text
+
+ def initialize(raw_text)
+ @raw_text = raw_text.to_s
+ end
+
+ def text
+ @raw_text
+ end
+
+ def movie_references
+ # is this the high road?
+ text.scan(/((sm|nm)\d{1,})/).map {|e| e[0]}
+ end
+
+ def mylist_references
+ text.scan(/(?<=mylist\/)\d{1,}/).map(&:to_i)
+ end
+
+ def community_references
+ text.scan(/co\d{1,}/)
+ end
+
+ def seiga_references
+ text.scan(/im\d{1,}/)
+ end
end
end
end
end
\ No newline at end of file