Module: Minpaso

Defined in:
lib/minpaso.rb

Defined Under Namespace

Classes: PCInfo, SearchResultPager

Constant Summary collapse

VERSION =
"002"

Class Method Summary collapse

Class Method Details

.search(params = {}) ⇒ Object

params

See minpaso.goga.co.jp/ja-JP/api.php for details.

  • :manufacturer

  • :product_name

  • :cpu_name

  • :graphics_adapter

  • :wei_min

  • :wei_max

  • :cpu_min

  • :cpu_max

  • :memory_min

  • :memory_max

  • :game_min

  • :game_max

  • :hdd_min

  • :hdd_max

  • :total_min

  • :total_max

  • :s or :sort

  • :p or :page

  • :h

  • :e or :guess_score

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/minpaso.rb', line 30

def self.search(params={})
  uri = URI.parse("http://minpaso.goga.co.jp/api/search.php")
  params = params.inject(Hash.new) do |table, (k, v)|
    case k
    when :sort; table["s"] = v
    when :page; table["p"] = v
    when :guess_score; table["e"] = e
    else
      if k.to_s.size > 1
        table[k.to_s.capitalize.gsub(/_([a-z])/){$1.capitalize}] = v
      else
        table[k.to_s] = v
      end
    end
    table
  end
  keys = params.keys - ["Manufacturer", "ProductName", "CpuName", "GraphicsAdapter",
                        "WeiMin", "WeiMax", "CpuMin", "CpuMax", "MemoryMin",
                        "MemoryMax", "VideoMin", "VideoMax", "GameMin", "GameMax",
                        "HddMin", "HddMax", "TotalMin", "TotalMax", "s", "p",
                        "h", "e"]
  raise ArgumentError, keys if keys.size > 0
  uri.query = params.map{|k, v| k + "=" + v.to_s}.join("&")
  SearchResultPager.new(REXML::Document.new(uri.read), params)
end