Class: QiitaExport::Fetcher::KobitoFetcher

Inherits:
Base
  • Object
show all
Defined in:
lib/qiita-export/fetcher/kobito_fetcher.rb

Constant Summary collapse

SELECT =
<<-"EOS"
  SELECT
    i.zurl,
    i.ztitle,
    i.zraw_body,
    i.zbody,
    i.zposted_at,
    i.zcreated_at,
    i.zupdated_at,
    i.zupdated_at_on_qiita,
    t.zurl_name
  FROM 
    zitem i left outer join zteam t on i.zteam = t.z_pk
  WHERE
    zin_trash is null
EOS
ORDER =
" ORDER BY i.zcreated_at"

Instance Method Summary collapse

Methods inherited from Base

#exclude?, #initialize

Constructor Details

This class inherits a constructor from QiitaExport::Fetcher::Base

Instance Method Details

#find_articlesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/qiita-export/fetcher/kobito_fetcher.rb', line 28

def find_articles
  where = if team?
            " and zurl_name = :team"
          else
            " and zteam is null"
          end
  query = "#{SELECT}#{where}#{ORDER}"

  db = SQLite3::Database.new(kobito_db)
  db.results_as_hash = true

  stmt = db.prepare(query)
  stmt.bind_param("team", team_name) if team?
  rs = stmt.execute

  articles = []
  while(row = rs.next)
    article =  to_article(row)
    articles << article unless exclude?(article.title)
  end
  articles
ensure
  stmt.close if stmt
  db.close   if db
end