Skip to content

Commit

Permalink
Clean up all code for creating new version
Browse files Browse the repository at this point in the history
  • Loading branch information
r7kamura committed Apr 27, 2014
1 parent fa37420 commit 8fd1b98
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 1,863 deletions.
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,3 +1,3 @@
source "http://rubygems.org"
source "https://rubygems.org"

gemspec
4 changes: 2 additions & 2 deletions LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2012 Ryo NAKAMURA
Copyright (c) 2014 Ryo NAKAMURA

MIT License

Expand All @@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 changes: 1 addition & 22 deletions Rakefile
@@ -1,26 +1,5 @@
#!/usr/bin/env rake

require "bundler/gem_tasks"

begin
require "bundler"
rescue LoadError
$stderr.puts e.message
$stderr.puts "Run `gem install bundler` to install bundler"
exit e.status_code
end

begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end

require "rspec/core"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
29 changes: 0 additions & 29 deletions example/search_by_keyword.rb

This file was deleted.

34 changes: 0 additions & 34 deletions example/search_saisoku.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/syoboi_calendar.rb
@@ -1,6 +1 @@
require "mechanize"
require "syoboi_calendar/agent"
require "syoboi_calendar/client"
require "syoboi_calendar/program"
require "syoboi_calendar/title"
require "syoboi_calendar/version"
55 changes: 0 additions & 55 deletions lib/syoboi_calendar/agent.rb

This file was deleted.

98 changes: 15 additions & 83 deletions lib/syoboi_calendar/client.rb
@@ -1,98 +1,30 @@
require "faraday"

module SyoboiCalendar
class Client
# user and pass are optional to search with user's channel setting
def initialize(opts = {})
@agent = Agent.new(:user => opts[:user], :pass => opts[:pass])
end
attr_reader :options

def login?
@agent.login?
def initialize(options = {})
@options = options
end

# search programs
def search(args)
query = create_search_query(args)
page = @agent.search(query)

args[:mode] == :title ?
extract_titles(page) :
extract_programs(page)
# TODO
def channels
end

private

# return Array of #<SyoboiCalendar::Program> by #<Mechanize::Page>
def extract_programs(page, opts = {})
page.search(".tframe tr").map do |tr|
args = {}

tr.search("td:nth-child(2) a").each do |a|
if match = a.attributes["href"].value.match(%r|/tid/(\d+)/time#(\d+)$|)
args[:tid] = match[1]
args[:pid] = match[2]
args[:name] = a.text
end
end

tr.search("td:nth-child(3)").each do |td|
args[:channel_name] = td.text
end

if args.has_key?(:tid)
Program.new(args)
else
nil
end
end.compact
# TODO
def programs
end

# return Array of #<SyoboiCalendar::Title> by #<Mechanize::Page>
def extract_titles(page, opts = {})
page.search(".tframe tr").map do |tr|
args = {}

tr.search("td:nth-child(1) a").each do |a|
if match = a.attributes["href"].value.match(%r|/tid/(\d+)$|)
args[:tid] = match[1]
args[:name] = a.text
end
end

if args.has_key?(:tid)
Title.new(args)
else
nil
end
end.compact
# TODO
def titles
end

# create hash for search query
def create_search_query(opts)
opts[:range] &&= canonicalize_range(opts[:range])

{
:sd => { nil => 2, :program => 2, :title => 0 }[opts[:mode]],
:r => { nil => 0, :all => 0, :past => 1, :future => 2}[opts[:range]] || 3,
:rd => opts[:range],
:kw => opts[:keyword],
:ch => opts[:channel],
:st => opts[:subtitle],
:cm => opts[:comment],
:uuc => opts[:uuc] || 1, # use user's channel setting
:v => opts[:v] || 0, # list view
:pfn => opts[:first] && 2, # first episode
:pfl => opts[:final] && 4, # final episode
:pfs => opts[:special] && 1, # special program
}.select { |k, v| v }
end
private

def canonicalize_range(range)
if range.kind_of?(Range)
[range.first, range.last].map { |date|
date.strftime("%Y/%m/%d")
}.join("-")
else
range
def connection
@connection ||= Faraday.new do |connection|
connection.adapter :net_http
end
end
end
Expand Down
86 changes: 0 additions & 86 deletions lib/syoboi_calendar/program.rb

This file was deleted.

0 comments on commit 8fd1b98

Please sign in to comment.