Class: QiitaTrend::Trend
- Inherits:
-
Object
- Object
- QiitaTrend::Trend
- Defined in:
- lib/qiita_trend/trend.rb
Overview
Qiitaのトレンドの機能を提供する
Instance Attribute Summary collapse
-
#data ⇒ Array
readonly
トレンドデータ.
Instance Method Summary collapse
-
#initialize(trend_type = TrendType::DAILY, date = nil) ⇒ Trend
constructor
コンストラクタ.
-
#items ⇒ Array
Qiitaの対象のトレンドをすべて取得.
-
#new_items ⇒ Array
Qiitaの対象のトレンドからNEWのものだけ取得.
Constructor Details
#initialize(trend_type = TrendType::DAILY, date = nil) ⇒ Trend
コンストラクタ
20 21 22 23 24 25 26 |
# File 'lib/qiita_trend/trend.rb', line 20 def initialize(trend_type = TrendType::DAILY, date = nil) page = Page.new(trend_type, date) parsed_html = Nokogiri::HTML.parse(page.html) trends_data = JSON.parse(parsed_html.xpath('//div[@data-hyperapp-app="Trend"]')[0]['data-hyperapp-props']) @data = trends_data['trend']['edges'] end |
Instance Attribute Details
#data ⇒ Array (readonly)
Returns トレンドデータ.
12 13 14 |
# File 'lib/qiita_trend/trend.rb', line 12 def data @data end |
Instance Method Details
#items ⇒ Array
Qiitaの対象のトレンドをすべて取得
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/qiita_trend/trend.rb', line 31 def items @data.each_with_object([]) do |trend, value| result = {} result['title'] = trend['node']['title'] result['user_name'] = trend['node']['author']['urlName'] result['user_image'] = user_image(trend['node']['author']['profileImageUrl']) result['user_page'] = "#{Page::QIITA_URI}#{trend['node']['author']['urlName']}" result['article'] = "#{Page::QIITA_URI}#{trend['node']['author']['urlName']}/items/#{trend['node']['uuid']}" result['created_at'] = trend['node']['createdAt'] result['likes_count'] = trend['node']['likesCount'] result['is_new_arrival'] = trend['isNewArrival'] value << result end end |
#new_items ⇒ Array
Qiitaの対象のトレンドからNEWのものだけ取得
49 50 51 52 53 |
# File 'lib/qiita_trend/trend.rb', line 49 def new_items items.select do |trend| trend['is_new_arrival'] == true end end |