minpaso 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.1.0 2007-12-31
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,3 @@
1
+ Copyright (c) 2007 Keita Yamaguchi
2
+
3
+ ruby-minpaso is released under the Ruby license.
data/Manifest.txt ADDED
@@ -0,0 +1,26 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/minpaso.rb
9
+ lib/minpaso/version.rb
10
+ log/debug.log
11
+ script/destroy
12
+ script/generate
13
+ script/txt2html
14
+ setup.rb
15
+ spec/minpaso_spec.rb
16
+ spec/spec.opts
17
+ spec/spec_helper.rb
18
+ tasks/deployment.rake
19
+ tasks/environment.rake
20
+ tasks/rspec.rake
21
+ tasks/website.rake
22
+ website/index.html
23
+ website/index.txt
24
+ website/javascripts/rounded_corners_lite.inc.js
25
+ website/stylesheets/screen.css
26
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,17 @@
1
+ = README
2
+
3
+ Authors:: Keita Yamaguchi(山口慶太)
4
+ Copyright:: Copyright (C) Keita Yamaguchi, 2007. All rights reserved.
5
+ License:: Ruby License
6
+
7
+ == What
8
+
9
+ ruby-minpaso is a wrapper library for Minpaso API.
10
+
11
+ == Links
12
+
13
+ * {Minpaso}[http://minpaso.goga.co.jp/]
14
+ * {API}[http://minpaso.goga.co.jp/ja-JP/api.php]
15
+ * ruby-minpaso
16
+ {Website}[http://minpaso.rubyforge.org/]
17
+ {Rubyforge Project}[http://rubyforge.org/projects/minpaso/]
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,72 @@
1
+ require 'minpaso/version'
2
+
3
+ AUTHOR = 'Keita Yamaguchi' # can also be an array of Authors
4
+ EMAIL = "keita.yamaguchi@gmail.com"
5
+ DESCRIPTION = "description of gem"
6
+ GEM_NAME = 'minpaso' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'minpaso' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "unknown"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = Minpaso::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'minpaso documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.author = AUTHOR
52
+ p.description = DESCRIPTION
53
+ p.email = EMAIL
54
+ p.summary = DESCRIPTION
55
+ p.url = HOMEPATH
56
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
57
+ p.test_globs = ["test/**/test_*.rb"]
58
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
59
+
60
+ # == Optional
61
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
62
+ # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
63
+ p.extra_deps = [['units', '>= 1.0.1']]
64
+
65
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
66
+
67
+ end
68
+
69
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+
17
+ require 'minpaso'
data/lib/minpaso.rb ADDED
@@ -0,0 +1,209 @@
1
+ require "open-uri"
2
+ require "uri"
3
+ require "rexml/document"
4
+ require "units/standard"
5
+
6
+ module Minpaso
7
+ # params:: See http://minpaso.goga.co.jp/ja-JP/api.php for details.
8
+ # - :manufacturer
9
+ # - :product_name
10
+ # - :cpu_name
11
+ # - :graphics_adapter
12
+ # - :wei_min
13
+ # - :wei_max
14
+ # - :cpu_min
15
+ # - :cpu_max
16
+ # - :memory_min
17
+ # - :memory_max
18
+ # - :game_min
19
+ # - :game_max
20
+ # - :hdd_min
21
+ # - :hdd_max
22
+ # - :total_min
23
+ # - :total_max
24
+ # - :s or :sort
25
+ # - :p or :page
26
+ # - :h
27
+ # - :e or :guess_score
28
+ def self.search(params={})
29
+ uri = URI.parse("http://minpaso.goga.co.jp/api/search.php")
30
+ params = params.inject(Hash.new) do |table, (k, v)|
31
+ case k
32
+ when :sort; table["s"] = v
33
+ when :page; table["p"] = v
34
+ when :guess_score; table["e"] = e
35
+ else
36
+ if k.to_s.size > 1
37
+ table[k.to_s.capitalize.gsub(/_([a-z])/){$1.capitalize}] = v
38
+ else
39
+ table[k.to_s] = v
40
+ end
41
+ end
42
+ table
43
+ end
44
+ keys = params.keys - ["Manufacturer", "ProductName", "CpuName", "GraphicsAdapter",
45
+ "WeiMin", "WeiMax", "CpuMin", "CpuMax", "MemoryMin",
46
+ "MemoryMax", "VideoMin", "VideoMax", "GameMin", "GameMax",
47
+ "HddMin", "HddMax", "TotalMin", "TotalMax", "s", "p",
48
+ "h", "e"]
49
+ raise ArgumentError, keys if keys.size > 0
50
+ uri.query = params.map{|k, v| k + "=" + v.to_s}.join("&")
51
+ SearchResultPager.new(REXML::Document.new(uri.read), params)
52
+ end
53
+
54
+ class SearchResultPager
55
+ class Item
56
+ attr_reader :id, :manufacture, :product_name, :wei_score, :cpu_score
57
+ attr_reader :memory_score, :video_score, :game_score, :hdd_score
58
+ attr_reader :total_score
59
+
60
+ def initialize(elt)
61
+ elt.elements.each do |e|
62
+ case e.name
63
+ when "ItemId"; @id = e.text.to_i
64
+ when "Manufacture"; @manufacture = e.text
65
+ when "ProductName"; @product_name = e.text
66
+ when "WeiScore"; @wei_score = e.text.to_f
67
+ when "CpuScore"; @cpu_score = e.text.to_f
68
+ when "MemoryScore"; @memory_score = e.text.to_f
69
+ when "VideoScore"; @video_score = e.text.to_f
70
+ when "GameScore"; @game_score = e.text.to_f
71
+ when "HddScore"; @hdd_score = e.text.to_f
72
+ when "TotalScore"; @total_score = e.text.to_f
73
+ end
74
+ end
75
+ end
76
+
77
+ # Qeury the PC detail informations.
78
+ def pcinfo(guess_score = true)
79
+ Minpaso::PCInfo.new(@id, guess_score)
80
+ end
81
+ end
82
+
83
+ attr_reader :size, :items
84
+ def initialize(doc, params)
85
+ @params = params
86
+ @items = []
87
+ doc.root.elements.each do |elt|
88
+ case elt.name
89
+ when "NumOfResult"
90
+ @size = elt.text.to_i
91
+ when "Item"
92
+ @items << Item.new(elt)
93
+ end
94
+ end
95
+ end
96
+
97
+ def page
98
+ @params.has_key?("p") ? @params["p"] : 1
99
+ end
100
+
101
+ # Go to previous page.
102
+ def prev
103
+ prev_page = page - 1
104
+ return nil if prev_page <= 0
105
+ Minpaso.search(@params.merge(:p => prev_page))
106
+ end
107
+
108
+ # Go to next page.
109
+ def next
110
+ next_page = page + 1
111
+ return nil if next_page >= ((@size - 1) / 10) + 1
112
+ Minpaso.search(@params.merge(:p => next_page))
113
+ end
114
+ end
115
+
116
+ # PCInfo shows PC detail informations.
117
+ class PCInfo
118
+ attr_reader :id, :guess_score, :system, :cpu, :graphics, :memory, :hdd
119
+
120
+ def initialize(id, guess_score = true)
121
+ @id = id
122
+ @guess_score = guess_score
123
+ uri = URI.parse("http://minpaso.goga.co.jp/api/pc.php?id=#{@id.to_s}&e=#{guess_score}")
124
+ doc = REXML::Document.new(uri.read)
125
+ doc.root.elements.each do |elt|
126
+ case elt.name
127
+ when "System"; @system = System.new(elt)
128
+ when "Cpu"; @cpu = CPU.new(elt)
129
+ when "Graphics"; @graphics = Graphics.new(elt)
130
+ when "Memory"; @memory = Memory.new(elt)
131
+ when "Hdd"; @hdd = HDD.new(elt)
132
+ end
133
+ end
134
+ end
135
+
136
+ class System
137
+ attr_reader :score, :total_score, :manufacturer, :product_name, :os
138
+ def initialize(elt)
139
+ elt.elements.each do |e|
140
+ case e.name
141
+ when "Score"; @score = e.text.to_f
142
+ when "TotalScore"; @total_score = e.text.to_f
143
+ when "Manufacturer"; @manufacturer = e.text
144
+ when "ProductName"; @product_name = e.text
145
+ when "Os"; @os = e.text
146
+ end
147
+ end
148
+ end
149
+ end
150
+
151
+ class CPU
152
+ attr_reader :score, :processor_name
153
+ def initialize(elt)
154
+ elt.elements.each do |e|
155
+ case e.name
156
+ when "Score"; @score = e.text.to_f
157
+ when "ProcessorName"; @processor_name = e.text
158
+ end
159
+ end
160
+ end
161
+ end
162
+
163
+ class Memory
164
+ attr_reader :score, :size
165
+ def initialize(elt)
166
+ elt.elements.each do |e|
167
+ case e.name
168
+ when "Score"; @score = e.text.to_f
169
+ when "Size"; @size = e.text.to_i.byte
170
+ end
171
+ end
172
+ end
173
+ end
174
+
175
+ class Graphics
176
+ attr_reader :video_score, :game_score, :adapter, :driver_version
177
+ attr_reader :total_graphics_memory, :dedicated_video_memory
178
+ attr_reader :dedicated_system_memory, :shared_system_memory
179
+ def initialize(elt)
180
+ elt.elements.each do |e|
181
+ case e.name
182
+ when "VideoScore"; @video_score = e.text.to_f
183
+ when "GameScore"; @game_score = e.text.to_f
184
+ when "Adapter"; @adapter = e.text
185
+ when "DriverVersion"; @driver_version = e.text
186
+ when "TotalGraphicsMemory"; @total_graphics_memory = e.text.to_i.byte
187
+ when "DedicatedVideoMemory"; @dedicated_video_memory = e.text.to_i.byte
188
+ when "DedicatedSystemMemory"; @dedicated_system_memory = e.text.to_i.byte
189
+ when "SharedSystemMemory"; @shared_system_memory = e.text.to_i.byte
190
+ end
191
+ end
192
+ end
193
+ end
194
+
195
+ class HDD
196
+ attr_reader :score, :primary_size, :primary_free_space, :total_size
197
+ def initialize(elt)
198
+ elt.elements.each do |e|
199
+ case e.name
200
+ when "Score"; @score = e.text.to_f
201
+ when "PrimarySize"; @primary_size = e.text.to_i.byte
202
+ when "PrimaryFreeSpace"; @primary_free_space = e.text.to_i.byte
203
+ when "TotalSize"; @total_size = e.text.to_i.byte
204
+ end
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,9 @@
1
+ module Minpaso #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/log/debug.log ADDED
File without changes
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ begin
5
+ require 'newgem'
6
+ rescue LoadError
7
+ puts "\n\nGenerating the website requires the newgem RubyGem"
8
+ puts "Install: gem install newgem\n\n"
9
+ exit(1)
10
+ end
11
+ require 'redcloth'
12
+ require 'syntax/convertors/html'
13
+ require 'erb'
14
+ require File.dirname(__FILE__) + '/../lib/minpaso/version.rb'
15
+
16
+ version = Minpaso::VERSION::STRING
17
+ download = 'http://rubyforge.org/projects/minpaso'
18
+
19
+ class Fixnum
20
+ def ordinal
21
+ # teens
22
+ return 'th' if (10..19).include?(self % 100)
23
+ # others
24
+ case self % 10
25
+ when 1: return 'st'
26
+ when 2: return 'nd'
27
+ when 3: return 'rd'
28
+ else return 'th'
29
+ end
30
+ end
31
+ end
32
+
33
+ class Time
34
+ def pretty
35
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
+ end
37
+ end
38
+
39
+ def convert_syntax(syntax, source)
40
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
+ end
42
+
43
+ if ARGV.length >= 1
44
+ src, template = ARGV
45
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
46
+
47
+ else
48
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
49
+ exit!
50
+ end
51
+
52
+ template = ERB.new(File.open(template).read)
53
+
54
+ title = nil
55
+ body = nil
56
+ File.open(src) do |fsrc|
57
+ title_text = fsrc.readline
58
+ body_text = fsrc.read
59
+ syntax_items = []
60
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
61
+ ident = syntax_items.length
62
+ element, syntax, source = $1, $2, $3
63
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
64
+ "syntax-temp-#{ident}"
65
+ }
66
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
67
+ body = RedCloth.new(body_text).to_html
68
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
69
+ end
70
+ stat = File.stat(src)
71
+ created = stat.ctime
72
+ modified = stat.mtime
73
+
74
+ $stdout << template.result(binding)