storexplore 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7da700982a0fbe6f80b7aa37ff7e4f231f43935
4
- data.tar.gz: 5fdb4f7684e506964f3fff42bdde441f70e71e92
3
+ metadata.gz: 7ffcb1b7ac49f590bdeafde98b7c6e3f6a4aecb8
4
+ data.tar.gz: fbb03b9a51c7eab05ffea0d1498cf5b8f15413ec
5
5
  SHA512:
6
- metadata.gz: 97e8fe6604856ffe5c4baa1287fe40ce5cfe40c4a950af74496bf848b3e42210973b218a117fc9a011d17814f82ca499e141fe810035e78a1d76a6bc45c58170
7
- data.tar.gz: c5645631ef4ec8569277f15c2d7b9354f26a134833ee79e9cefd52ac0b3fea37919fabe8d51eab67be94479dd18c8cf2400aa8ca362d6aca846c6c1e41971c79
6
+ metadata.gz: 94933a0836b830b49ac03fe4f604bf9f8be35cf6e1518a1ceb92b42ae03f76deb7d10e7e9a38cbff4753ea1a8eb3c4607d82445e28397ff3e45f1053bb2306ce
7
+ data.tar.gz: 94c3a3291e638198fba5b19071449eeaa40cfbaac57db6cb28cb4f7294c515d4a895524448e618aad404dd412bff240eb386e99a329046dda79ba2a0e2e2766e
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/storexplore.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # storexplore.rb
4
4
  #
5
- # Copyright (c) 2010, 2011, 2012, 2013, 2014 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2010-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # api.rb
4
4
  #
5
- # Copyright (c) 2010, 2011, 2012, 2013, 2014 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2010-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -21,35 +21,31 @@
21
21
 
22
22
  module Storexplore
23
23
 
24
- # Objects able to walk a store and discover available items
24
+ # Main entry point to the library
25
25
  class Api
26
26
 
27
+ # Defines a new store API, with a name and a definition inside the given
28
+ # block. The block is evaluated in the context of a Storexplore::Dsl
29
+ # instance, see README
27
30
  def self.define(name, &block)
28
31
  builder = Dsl.walker_builder(&block)
29
32
 
30
33
  register_builder(name, builder)
31
34
  end
32
35
 
36
+ # Starts to browse a real store. Uses the first defined API whose name is
37
+ # included in the url of the store.
38
+ # Returns a Storexplore::Walker for the home page of the store
33
39
  def self.browse(store_url)
34
40
  builder(store_url).new_walker(WalkerPage.open(store_url))
35
41
  end
36
42
 
43
+ # Forgets the previously defined store API by its name. Mainly useful while
44
+ # testing.
37
45
  def self.undef(name)
38
46
  builders.delete(name)
39
47
  end
40
48
 
41
- # Uri of the main page of the store
42
- # def uri
43
-
44
- # Attributes of the page
45
- # def attributes
46
-
47
- # Walkers of the root categories of the store
48
- # def categories
49
-
50
- # Walkers of the root items in the store
51
- # def items
52
-
53
49
  private
54
50
 
55
51
  def self.register_builder(name, builder)
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # array_utils.rb
4
4
  #
5
- # Copyright (c) 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2012-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # browsing_error.rh
4
4
  #
5
- # Copyright (c) 2011, 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2011-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -20,7 +20,8 @@
20
20
  # MA 02110-1301 USA
21
21
 
22
22
  module Storexplore
23
- # Error thrown when store item browsing fails due to unexpected page formatting
23
+ # Exception thrown by Storexplore::Walker when store item browsing fails due
24
+ # to unexpected page formatting
24
25
  class BrowsingError < StandardError
25
26
  end
26
27
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # digger.rb
4
4
  #
5
- # Copyright (c) 2010, 2011, 2012, 2013, 2014 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2010-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # dsl.rb
4
4
  #
5
- # Copyright (c) 2011, 2012, 2013, 2014 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2011-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -21,32 +21,51 @@
21
21
 
22
22
  module Storexplore
23
23
 
24
+ # Implementation of the DSL used to define new APIs on real web stores.
25
+ # See README for examples
24
26
  class Dsl
25
27
 
28
+ # Starts the definition of the API. Evaluates the block with the
29
+ # context of an instance of Storexplore::Dsl
26
30
  def self.walker_builder(&block)
27
31
  new.tap do |dsl|
28
32
  dsl.instance_eval(&block)
29
33
  end
30
34
  end
31
35
 
32
- def initialize()
36
+ # Initializes a new instance with no special categories, items or
37
+ # attributes definition. (Internal usage)
38
+ def initialize
33
39
  @scrap_attributes_block = lambda do |_| {} end
34
40
  @categories_digger = NullDigger.new
35
41
  @items_digger = NullDigger.new
36
42
  end
37
43
 
44
+ # Registers the block to be used to extract attributes from a store page.
45
+ # Block will be evaluated within the context of a Storexplore::WalkerPage
38
46
  def attributes(&block)
39
47
  @scrap_attributes_block = block
40
48
  end
41
49
 
50
+ # Defines how to find child categories.
51
+ # * selector is the nokogiri selector to match links to these categories
52
+ # * the block defines how to scrap these children categories, will
53
+ # be evaluated within the context of the child Storexplore::Dsl instance
42
54
  def categories(selector, &block)
43
55
  @categories_digger = Digger.new(selector, Dsl.walker_builder(&block))
44
56
  end
45
57
 
58
+ # Same as #categories, but for child items
46
59
  def items(selector, &block)
47
60
  @items_digger = Digger.new(selector, Dsl.walker_builder(&block))
48
61
  end
49
62
 
63
+ # Initializes a new Storexplore::Walker instance based on specified custom
64
+ # definitions from the instance.
65
+ # * page_getter : proxy to the page that we want to explore
66
+ # * father : parent Storexplore::Walker instance (troubleshouting)
67
+ # * index : index of the page within its brothers
68
+ # (Internal usage)
50
69
  def new_walker(page_getter, father = nil, index = nil)
51
70
  Walker.new(page_getter).tap do |walker|
52
71
  walker.categories_digger = @categories_digger
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # hash_utils.rb
4
4
  #
5
- # Copyright (c) 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2012-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # null_digger.rb
4
4
  #
5
- # Copyright (c) 2010, 2011, 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2010-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # storexplore.rb
4
4
  #
5
- # Copyright (c) 2010, 2011, 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2010-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # api_shared_examples.rb
4
4
  #
5
- # Copyright (c) 2010, 2011, 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2010-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # configuration.rb
4
4
  #
5
- # Copyright (c) 2010, 2011, 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2013-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -22,8 +22,12 @@
22
22
  require 'logger'
23
23
 
24
24
  module Storexplore
25
+
26
+ # Extra facilities to ease testing custom store APIs.
25
27
  module Testing
26
28
 
29
+ # Call this with a block to initialize Storexplore::Testing. The given
30
+ # block receives the Storexplore::Testing::Configuration as argument.
27
31
  def self.config
28
32
  @config ||= Configuration.new
29
33
  yield @config if block_given?
@@ -37,18 +41,24 @@ module Storexplore
37
41
  @logger.level = Logger::INFO
38
42
  end
39
43
 
40
- # Generation directory where the dummy stores will be generated.
41
- # A sub folder with name DummyStore::NAME will be created there to hold all generated dummy stores,
42
- # the content of this directory will be deleted when the DummyStore.wipeout method is called
44
+ # Sets the generation directory where the dummy stores will be generated.
45
+ # A sub folder with name Storexplore::DummyStoreConstants#NAME will be
46
+ # created there to holdvall generated dummy stores, the content of this
47
+ # directory will be deleted when the Storexplore::DummyStore#wipeout
48
+ # method is called.
49
+ # This setup is required to use Storexplore::Testing.
50
+ def dummy_store_generation_dir=(generation_dir)
51
+ @generation_dir = generation_dir
52
+ end
53
+ # See #dummy_store_generation_dir=.
54
+ # Throws if no generation dir was previously set
43
55
  def dummy_store_generation_dir
44
56
  raise StandardError.new('You need to configure a dummy store generation directory with Storexplore::Testing.config.dummy_store_generation_dir=') if @generation_dir.nil?
45
57
  @generation_dir
46
58
  end
47
- def dummy_store_generation_dir=(generation_dir)
48
- @generation_dir = generation_dir
49
- end
50
59
 
51
- # Logger for custom test messages
60
+ # Logger for custom test messages. By default, it logs to STDOUT with
61
+ # info level.
52
62
  attr_accessor :logger
53
63
 
54
64
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # dummy_data.rb
4
4
  #
5
- # Copyright (c) 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2012-2013 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -22,12 +22,16 @@
22
22
  module Storexplore
23
23
  module Testing
24
24
 
25
+ # Dummy data generator for Storexplore::Testing::DummyStore store
26
+ # generation
25
27
  class DummyData
26
28
 
29
+ # A new unique name.
27
30
  def self.name(kind)
28
31
  "#{kind.capitalize}-#{new_int}"
29
32
  end
30
33
 
34
+ # A new unique set of standard store item attributes.
31
35
  def self.attributes(name, options)
32
36
  {
33
37
  name: name,
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # dummy_store.rb
4
4
  #
5
- # Copyright (c) 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2012-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -24,76 +24,102 @@ require "fileutils"
24
24
  module Storexplore
25
25
  module Testing
26
26
 
27
+ # Read / Write model for a disk html store page. Every modification is
28
+ # directly saved to the disk, nothing remains in memory.
29
+ # All stores are generated in a specific subdirectory of
30
+ # Storexplore::Testing::Configuration #dummy_store_generation_dir /
31
+ # Storexplore::Testing::DummyStoreConstants #NAME
27
32
  class DummyStore
28
33
 
34
+ # Initializes or opens a dummy store in the 'store_name' subdirectory
29
35
  def self.open(store_name)
30
36
  new(root_path(store_name), store_name)
31
37
  end
32
38
 
39
+ # file:// uri for the place where the 'store_name' store would be
40
+ # created
33
41
  def self.uri(store_name)
34
42
  "file://#{root_path(store_name)}"
35
43
  end
36
44
 
45
+ # Deletes from disk all generated dummy stores
37
46
  def self.wipe_out
38
47
  FileUtils.rm_rf(root_dir)
39
48
  end
49
+ # Deletes from disk the 'store_name' dummy store
40
50
  def self.wipe_out_store(store_name)
41
51
  FileUtils.rm_rf(root_path(store_name))
42
52
  end
43
53
 
54
+ # file:// uri of the page
44
55
  def uri
45
56
  "file://#{@path}"
46
57
  end
47
58
 
59
+ # Name of the page
48
60
  attr_reader :name
49
61
 
62
+ # Child Storexplore::Testing::DummyStore instances for existing sub
63
+ # categories
50
64
  def categories
51
65
  _name, categories, _items, _attributes = read
52
66
  categories.map do |category_name|
53
67
  DummyStore.new("#{absolute_category_dir(category_name)}/index.html", category_name)
54
68
  end
55
69
  end
70
+ # Child category Storexplore::Testing::DummyStore instance with the
71
+ # specified name. Creates it if it does not yet exist
56
72
  def category(category_name)
57
73
  short_category_name = short_name(category_name)
58
74
  add([short_category_name], [], {})
59
75
  DummyStore.new("#{absolute_category_dir(short_category_name)}/index.html", category_name)
60
76
  end
77
+ # Deletes the specified child category.
61
78
  def remove_category(category_name)
62
79
  short_category_name = short_name(category_name)
63
80
  remove([short_category_name], [], [])
64
81
  FileUtils.rm_rf(absolute_category_dir(short_category_name))
65
82
  end
66
83
 
84
+ # Child Storexplore::Testing::DummyStore instances for existing sub
85
+ # items
67
86
  def items
68
87
  _name, _categories, items, _attributes = read
69
88
  items.map do |item_name|
70
89
  DummyStore.new(absolute_item_file(item_name), item_name)
71
90
  end
72
91
  end
92
+ # Child item Storexplore::Testing::DummyStore instance with the
93
+ # specified name. Creates it if it does not yet exist
73
94
  def item(item_name)
74
95
  short_item_name = short_name(item_name)
75
96
  add([], [short_item_name], {})
76
97
  DummyStore.new(absolute_item_file(short_item_name), item_name)
77
98
  end
99
+ # Deletes the specified child item.
78
100
  def remove_item(item_name)
79
101
  short_item_name = short_name(item_name)
80
102
  remove([], [short_item_name], [])
81
103
  FileUtils.rm_rf(absolute_item_file(short_item_name))
82
104
  end
83
105
 
106
+ # Hash of the current attributes
84
107
  def attributes(*args)
85
108
  return add_attributes(args[0]) if args.size == 1
86
109
 
87
110
  _name, _categories, _items, attributes = read
88
111
  HashUtils.internalize_keys(attributes)
89
112
  end
113
+ # Adds the specified attributes
90
114
  def add_attributes(values)
91
115
  add([], [], HashUtils.stringify_keys(values))
92
116
  end
117
+ # Removes the specified attriutes
93
118
  def remove_attributes(*attribute_names)
94
119
  remove([], [], ArrayUtils.stringify(attribute_names))
95
120
  end
96
121
 
122
+ # New Storexplore::Testing::DummyStoreGenerator instance for this
97
123
  def generate(count = 1)
98
124
  DummyStoreGenerator.new([self], count)
99
125
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # dummy_store_api.rb
4
4
  #
5
- # Copyright (c) 2012, 2013, 2014 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2012-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -24,6 +24,9 @@ require_relative 'dummy_store_constants'
24
24
  module Storexplore
25
25
  module Testing
26
26
 
27
+ # API definition for stores generated Storexplore::DummyStore
28
+ # This file can be included on its own, without storexplore/testing.rb and
29
+ # without the need for all the runtime testing dependencies (rspec, etc).
27
30
  Storexplore::Api.define DummyStoreConstants::NAME do
28
31
 
29
32
  categories 'a.category' do
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # dummy_store_constants.rb
4
4
  #
5
- # Copyright (c) 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2013-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # dummy_store_generator.rb
4
4
  #
5
- # Copyright (c) 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2012-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -22,27 +22,41 @@
22
22
  module Storexplore
23
23
  module Testing
24
24
 
25
+ # Dummy store generation one liner. Forwards chains of method calls to a
26
+ # collections of Storexplore::Testing::DummyStore instances.
25
27
  class DummyStoreGenerator
28
+
29
+ # * pages : collection of Storexplore::Testing::DummyStore instances to
30
+ # which calls will be forwarded
31
+ # * count : number of children (categories or items) that will be added
32
+ # with every generation call
26
33
  def initialize(pages, count = 1)
27
34
  @pages = pages
28
35
  @count = count
29
36
  end
30
37
 
38
+ # Changes the number of generated children
31
39
  def and(count)
32
40
  @count = count
33
41
  self
34
42
  end
35
43
 
44
+ # Generates @count categories on all @pages
36
45
  def categories
37
46
  dispatch(:category)
38
47
  end
48
+ # See #categories
39
49
  alias_method :category, :categories
40
50
 
51
+ # Generates @count items with attributes on all @pages
41
52
  def items
42
53
  dispatch(:item).attributes
43
54
  end
55
+ # See #items
44
56
  alias_method :item, :items
45
57
 
58
+ # generates attributes for all @pages. Explicit attributes can be
59
+ # specified
46
60
  def attributes(options = {})
47
61
  @pages.map do |page|
48
62
  attributes = DummyData.attributes(page.name, options)
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # have_unique_matcher.rb
4
4
  #
5
- # Copyright (c) 2010, 2011, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2010-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # mostly_matcher.rb
4
4
  #
5
- # Copyright (c) 2010, 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2010-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # uri.rb
4
4
  #
5
- # Copyright (c) 2011, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2011-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # version.rb
4
4
  #
5
- # Copyright (c) 2010, 2011, 2012, 2013, 2014 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2010-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -20,5 +20,5 @@
20
20
  # MA 02110-1301 USA
21
21
 
22
22
  module Storexplore
23
- VERSION = "0.1.0"
23
+ VERSION = "0.1.1"
24
24
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # walker.rb
4
4
  #
5
- # Copyright (c) 2010, 2011, 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2010-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -21,8 +21,10 @@
21
21
 
22
22
  module Storexplore
23
23
 
24
+ # Objects representing categories and items of the store. These are the instances manipulated when browsing a previously defined store
24
25
  class Walker
25
26
 
27
+ # Internal usage
26
28
  attr_accessor :categories_digger, :items_digger, :scrap_attributes_block, :father, :index
27
29
 
28
30
  def initialize(getter)
@@ -32,30 +34,42 @@ module Storexplore
32
34
  @getter = getter
33
35
  end
34
36
 
37
+ # Early title, accessible before the page is loaded.
38
+ # * for the store root, this is the store uri
39
+ # * for other pages, it's the caption of the link that brought to this
35
40
  def title
36
41
  @getter.text
37
42
  end
38
43
 
44
+ # Full uri of the page being browsed
39
45
  def uri
40
46
  page.uri
41
47
  end
42
48
 
49
+ # Scraped attributes of this page. Attributes are extracted with the
50
+ # corresponding attributes blocks given in Storexplore::Dsl
43
51
  def attributes
44
52
  @attributes ||= scrap_attributes
45
53
  end
46
54
 
55
+ # Sub categories Storexplore::Walker, as matched by the corresponding
56
+ # categories selector in Storexplore::Dsl
47
57
  def categories
48
58
  categories_digger.sub_walkers(page, self)
49
59
  end
50
60
 
61
+ # Sub items Storexplore::Walker, as matched by the corresponding
62
+ # categories selector in Storexplore::Dsl
51
63
  def items
52
64
  items_digger.sub_walkers(page, self)
53
65
  end
54
66
 
67
+ # String representation with uri and index among siblings.
55
68
  def to_s
56
69
  "#{self.class} ##{index} @#{uri}"
57
70
  end
58
71
 
72
+ # Extended multiline string representation with parents.
59
73
  def genealogy
60
74
  genealogy_prefix + to_s
61
75
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # walker_page.rb
4
4
  #
5
- # Copyright (c) 2010, 2011, 2012, 2013, 2014 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2010-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -23,15 +23,22 @@ require 'mechanize'
23
23
 
24
24
  module Storexplore
25
25
 
26
+ # Wrapper around Mechanize::Page providing strict one liners to select
27
+ # elements.
26
28
  class WalkerPage
27
29
  extend Forwardable
28
30
 
31
+ # A new lazy proxy on the page.
32
+ # (Internal Usage)
29
33
  def self.open(uri)
30
34
  Getter.new(uri)
31
35
  end
32
36
 
37
+ # Uri of the page
33
38
  def_delegator :@mechanize_page, :uri
34
39
 
40
+ # Collection of proxies on pages accessible through the matching links
41
+ # (Internal Usage)
35
42
  def search_links(selector)
36
43
  uri2links = {}
37
44
  search_all_links(selector).each do |link|
@@ -42,10 +49,14 @@ module Storexplore
42
49
  uri2links.values.sort_by {|link| link.uri.to_s }
43
50
  end
44
51
 
52
+ # Unique element matching selector
53
+ # Throws Storexplore::WalkerPageError if there is not exactly one matching
54
+ # element
45
55
  def get_one(selector)
46
56
  first_or_throw(@mechanize_page.search(selector), "elements", selector)
47
57
  end
48
58
 
59
+ # String with the text of all matching elements, separated by separator.
49
60
  def get_all(selector, separator)
50
61
  elements = @mechanize_page.search(selector)
51
62
  throw_if_empty(elements, "elements", selector)
@@ -53,6 +64,9 @@ module Storexplore
53
64
  (elements.map &:text).join(separator)
54
65
  end
55
66
 
67
+ # Unique image matching selector
68
+ # Throws Storexplore::WalkerPageError if there is not exactly one matching
69
+ # image
56
70
  def get_image(selector)
57
71
  first_or_throw(@mechanize_page.images_with(search: selector), "images", selector)
58
72
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # walker_page_error.rb
4
4
  #
5
- # Copyright (c) 2010, 2011, 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2010-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -20,6 +20,8 @@
20
20
  # MA 02110-1301 USA
21
21
 
22
22
  module Storexplore
23
+ # Exception thrown by Storexplore::WalkerPage when scrapping fails because
24
+ # the page does not match the expected format.
23
25
  class WalkerPageError < StandardError
24
26
  end
25
27
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # api_spec.rb
4
4
  #
5
- # Copyright (C) 2010, 2011, 2012, 2013, 2014 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (C) 2010-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # dsl_spec.rb
4
4
  #
5
- # Copyright (C) 2012, 2013, 2014 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (C) 2012-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # dummy_store_api_spec.rb
4
4
  #
5
- # Copyright (c) 2011, 2012, 2013, 2014 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2011-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # uri_utils.rb
4
4
  #
5
- # Copyright (c) 2011, 2012, 2013 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2011-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # walker_page_spec.rb
4
4
  #
5
- # Copyright (c) 2011, 2012, 2013, 2014 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2011-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # spec_helper.rb
4
4
  #
5
- # Copyright (c) 2013, 2014 by Philippe Bourgau. All rights reserved.
5
+ # Copyright (c) 2013-2014 by Philippe Bourgau. All rights reserved.
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storexplore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philou
@@ -31,7 +31,7 @@ cert_chain:
31
31
  yLcl1cmm5ALtJ/+Bkkmp0i4amXeTDMvq9r8PBsVsQwxYOYJBP+Umxz3PX6HjFHrQ
32
32
  XdkXx3oZ
33
33
  -----END CERTIFICATE-----
34
- date: 2014-01-14 00:00:00.000000000 Z
34
+ date: 2014-01-16 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mechanize
metadata.gz.sig CHANGED
Binary file