Class: YahooGroupData
- Inherits:
-
Object
- Object
- YahooGroupData
- Defined in:
- lib/yahoo-group-data.rb,
lib/yahoo-group-data/version.rb
Constant Summary collapse
- VERSION =
"1.4.1"
Instance Method Summary collapse
- #[](thing) ⇒ Object
- #age_restricted? ⇒ Boolean
- #category ⇒ Object
- #description ⇒ Object
- #founded ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize(url) ⇒ YahooGroupData
constructor
A new instance of YahooGroupData.
- #language ⇒ Object
- #name ⇒ Object
- #no_data? ⇒ Boolean
- #not_found? ⇒ Boolean
- #num_members ⇒ Object
- #owner_email ⇒ Object
- #post_email ⇒ Object
- #private? ⇒ Boolean
- #subscribe_email ⇒ Object
- #to_json ⇒ Object
- #unsubscribe_email ⇒ Object
Constructor Details
#initialize(url) ⇒ YahooGroupData
Returns a new instance of YahooGroupData.
10 11 12 13 14 15 16 17 18 |
# File 'lib/yahoo-group-data.rb', line 10 def initialize(url) raise ArgumentError "A URL must be passed" unless url curb = Curl::Easy.new(url) curb.follow_location = true curb.http_get @html = curb.body_str.force_encoding('iso-8859-1').encode("UTF-8") @response_code = curb.response_code end |
Instance Method Details
#[](thing) ⇒ Object
24 25 26 27 |
# File 'lib/yahoo-group-data.rb', line 24 def [](thing) return unless respond_to? thing send(thing) end |
#age_restricted? ⇒ Boolean
78 79 80 81 |
# File 'lib/yahoo-group-data.rb', line 78 def age_restricted? return nil if not_found? or matches_private? matches_age_restricted? end |
#category ⇒ Object
95 96 97 98 |
# File 'lib/yahoo-group-data.rb', line 95 def category return unless has_category? @category ||= no_data? ? nil : doc.xpath('//*[@id="yginfo"]/ul/li[2]/a').inner_html end |
#description ⇒ Object
37 38 39 40 41 42 |
# File 'lib/yahoo-group-data.rb', line 37 def description element = doc.css('span.ygrp-grdescr') if element.size > 0 doc.css('span.ygrp-grdescr').first.content.gsub(/\A[ยท\s]*/, "") end end |
#founded ⇒ Object
83 84 85 |
# File 'lib/yahoo-group-data.rb', line 83 def founded @founded ||= no_data? ? nil : Date.parse(date_str_to_english(doc.xpath("//ul[@class=\"ygrp-ul ygrp-info\"]//li[#{has_category? ? 3 : 2}]").inner_html.split(':')[1].strip)) end |
#has_key?(key) ⇒ Boolean
20 21 22 |
# File 'lib/yahoo-group-data.rb', line 20 def has_key?(key) respond_to? key end |
#language ⇒ Object
87 88 89 |
# File 'lib/yahoo-group-data.rb', line 87 def language @language ||= no_data? ? nil : doc.xpath("//ul[@class=\"ygrp-ul ygrp-info\"]//li[#{has_category? ? 4 : 3}]").inner_html.split(':')[1].strip end |
#name ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/yahoo-group-data.rb', line 29 def name @name ||= if not_found? || age_restricted? nil else doc.css('span.ygrp-pname').first.content end end |
#no_data? ⇒ Boolean
123 124 125 |
# File 'lib/yahoo-group-data.rb', line 123 def no_data? private? or age_restricted? or not_found? end |
#not_found? ⇒ Boolean
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/yahoo-group-data.rb', line 65 def not_found? @not_found ||= (response_was_404? || ( ( doc.xpath('/html/body/div[3]/div/div/div/h3').size > 0 and doc.xpath('/html/body/div[3]/div/div/div/h3').first.content.strip.match(/Group Not Found|Group nicht gefunden/i) ) || ( doc.xpath('//*[@id="bodyID"]/div[4]/div/div/div/h3').inner_html.strip.match(/Group Not Found|Group nicht gefunden/i) ) ) ? true : false ) end |
#num_members ⇒ Object
91 92 93 |
# File 'lib/yahoo-group-data.rb', line 91 def num_members @num_members ||= no_data? ? nil : Integer(doc.xpath('//ul[@class="ygrp-ul ygrp-info"]//li[1]').inner_html.split(':')[1]) end |
#owner_email ⇒ Object
52 53 54 |
# File 'lib/yahoo-group-data.rb', line 52 def owner_email @owner_email ||= no_data? ? nil : doc.css('div#ygrp-links div.ygrp-contentblock').first.content.match(/(\S*-owner@[a-z]*yahoo[a-z]*\.[a-z\.]+)/)[1] end |
#post_email ⇒ Object
44 45 46 |
# File 'lib/yahoo-group-data.rb', line 44 def post_email @post_email ||= no_data? ? nil : subscribe_email.gsub("-subscribe@", "@") end |
#private? ⇒ Boolean
60 61 62 63 |
# File 'lib/yahoo-group-data.rb', line 60 def private? return nil if not_found? || matches_age_restricted? matches_private? end |
#subscribe_email ⇒ Object
48 49 50 |
# File 'lib/yahoo-group-data.rb', line 48 def subscribe_email @subscribe_email ||= no_data? ? nil : doc.css('div#ygrp-links div.ygrp-contentblock').first.content.match(/(\S*-subscribe@[a-z]*yahoo[a-z]*\.[a-z\.]+)/)[1] end |
#to_json ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/yahoo-group-data.rb', line 100 def to_json data_methods = %w{ private? not_found? age_restricted? name description post_email subscribe_email owner_email unsubscribe_email language num_members category founded } data_hash = {} data_methods.map {|dm| data_hash[dm.tr('?', '')] = send(dm)} Yajl::Encoder.encode(data_hash) end |
#unsubscribe_email ⇒ Object
56 57 58 |
# File 'lib/yahoo-group-data.rb', line 56 def unsubscribe_email @unsubscribe_email ||= no_data? ? nil : doc.css('div#ygrp-links div.ygrp-contentblock').first.content.match(/(\S*-unsubscribe@[a-z]*yahoo[a-z]*\.[a-z\.]+)/)[1] end |