tamiyo 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9a4830a9859afcba9035ce3defb78b6e8378bf5
4
- data.tar.gz: 33970adda5c138a5e6acfe37507573ae90d78100
3
+ metadata.gz: 618214b3281617aedac786d889e18a10eb7bbc5f
4
+ data.tar.gz: 654aba2dd4153e722dbbd8362d030bb6b0547588
5
5
  SHA512:
6
- metadata.gz: e5ab665d41dea84def8882ba64d124369207596e517e39991c873a65f14b67463ab9fe25e7f3301f8f511c173fd2fc42b489af3f523a4fd1f3c076302b961adb
7
- data.tar.gz: eeb2d88c134bfb99cd1c32e0d0569337e5b2627975eeea42c2da3563407284b8783a01bf5662b0eac0ddf32171f79dc56bc8f9ae0209e35f1e8a418793f3dd8b
6
+ metadata.gz: 1c8222f4990cd353191dec4f803d7cabaf33f19f31e5686b2e9b0d8e2b10c580a47711526163f62f7b005075e72ac99e7f1950cf31e664ee5f1dfd75cd185076
7
+ data.tar.gz: 030b363179e31dd897532f5cb6cd02c4f811e1b169c13d30a8cb1eb453f7c40e536f7e9debb90a14539a92b739a28aa23eea509f8f0f647ab5cba603d2abdfb3
@@ -1,7 +1,15 @@
1
1
  require 'slop'
2
2
 
3
+ gem_name = File.basename __FILE__, '.rb'
4
+
5
+ def assuming_at_least(nr, args, opts)
6
+ valid = args.size >= nr
7
+ yield if valid && block_given?
8
+ puts opts unless valid
9
+ end
10
+
3
11
  opts = Slop.new help: true do
4
- banner "Usage: #{File.basename __FILE__} <command>"
12
+ banner "Usage: #{gem_name} [command]"
5
13
 
6
14
  command 'dummy-scrape' do
7
15
  run do |opts, args|
@@ -12,8 +20,9 @@ opts = Slop.new help: true do
12
20
 
13
21
  command 'gatherer-scrape' do
14
22
  run do |opts, args|
23
+ set = args.first || "Innistrad"
15
24
  require 'tamiyo/gatherer_scrape_chain'
16
- Tamiyo::GathererScrapeChain.create(args.first || "Innistrad").pump
25
+ Tamiyo::GathererScrapeChain.create(set).pump
17
26
  end
18
27
  end
19
28
 
@@ -25,12 +34,29 @@ opts = Slop.new help: true do
25
34
  end
26
35
 
27
36
  command 'add-set' do
37
+ banner "Usage: #{gem_name} add-set [abbr] [set name]"
38
+ run do |opts, args|
39
+ assuming_at_least(2, args, opts) do
40
+ abbr = args.shift.upcase
41
+ name = args.join(' ')
42
+ puts "Adding set #{abbr} => #{name}"
43
+ require 'tamiyo/sets'
44
+ Tamiyo::Sets.add_custom_set abbr, name
45
+ end
46
+ end
47
+ end
48
+
49
+ command 'remove-set' do
50
+ banner "Usage: #{gem_name} remove-set [ [abbr] | --name [set name] ]"
51
+ on :n, :name, 'Remove set by full name instead of abbrevation'
52
+
28
53
  run do |opts, args|
29
- require 'tamiyo/sets'
30
- abbr = args.shift.upcase
31
- name = args.join(' ')
32
- puts "Adding set #{abbr} => #{name}"
33
- Tamiyo::Sets.add_custom_set abbr, name
54
+ assuming_at_least(1, args, opts) do
55
+ name = opts.name? ? args.join(' ') : args.shift.upcase
56
+ puts "Removing set #{name}"
57
+ require 'tamiyo/sets'
58
+ Tamiyo::Sets.remove_custom_set name
59
+ end
34
60
  end
35
61
  end
36
62
  end
@@ -1,11 +1,11 @@
1
1
  require 'nokogiri'
2
2
  require 'tamiyo/process'
3
3
  require 'tamiyo/data_store'
4
+ require 'tamiyo/default_data'
4
5
 
5
6
  module Tamiyo
6
7
  class CockatriceDbSink
7
8
  include Process::Node
8
- include DataStore
9
9
 
10
10
  def pump
11
11
  content = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
@@ -19,7 +19,7 @@ module Tamiyo
19
19
 
20
20
  def add_sets_to(xml)
21
21
  xml.sets {
22
- default_set_data['sets'].each do |abbr, name|
22
+ DefaultData.sets['sets'].each do |abbr, name|
23
23
  xml.set {
24
24
  xml.name abbr
25
25
  xml.longname name
@@ -48,7 +48,8 @@ module Tamiyo
48
48
  end
49
49
 
50
50
  def store_xml(content)
51
- path = provide_path_for 'cards.xml'
51
+ data_store = DataStore.new
52
+ path = data_store.path_for 'cards.xml'
52
53
  File.open(path, 'w') do |file|
53
54
  file.write content.to_xml
54
55
  end
@@ -3,12 +3,36 @@ require 'tamiyo/yaml/yaml_helper'
3
3
 
4
4
  module Tamiyo
5
5
  class Sets
6
- def self.add_custom_set abbr, name
7
- @store ||= DataStore.new
8
- data = @store.load_custom_sets
9
- data['sets'] ||= {}
10
- data['sets'].store abbr, name
11
- @store.persist_custom_sets data
6
+ class << self
7
+ def add_custom_set(abbr, name)
8
+ @store ||= DataStore.new
9
+ data = @store.load_custom_sets
10
+ data['sets'] ||= {}
11
+ data['sets'].store abbr, name
12
+ @store.persist_custom_sets data
13
+ end
14
+
15
+ def remove_custom_set(name)
16
+ @store ||= DataStore.new
17
+ data = @store.load_custom_sets
18
+ modify_sets! data do |sets|
19
+ prune_set! sets, name
20
+ end
21
+ @store.persist_custom_sets data
22
+ end
23
+
24
+ def modify_sets!(data)
25
+ if block_given? && data.include?('sets')
26
+ yield data['sets']
27
+ data.delete 'sets' if data['sets'].empty?
28
+ end
29
+ end
30
+
31
+ def prune_set!(sets, name)
32
+ abbr = name.upcase
33
+ sets.delete(abbr) or
34
+ sets.delete_if { |_, value| value == name }
35
+ end
12
36
  end
13
37
  end
14
38
  end
@@ -1,3 +1,3 @@
1
1
  module Tamiyo
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -6,7 +6,6 @@ module Tamiyo
6
6
  module Yaml
7
7
  class YamlSink
8
8
  include Process::Node
9
- include DataStore
10
9
  include YamlHelper
11
10
 
12
11
  def pump
@@ -30,7 +29,8 @@ module Tamiyo
30
29
  end
31
30
 
32
31
  def with_the_cards_file(&block)
33
- file_name = provide_path_for 'cards.yaml'
32
+ store = DataStore.new
33
+ file_name = store.path_for 'cards.yaml'
34
34
  if block_given?
35
35
  File.open(file_name, 'w') do |file|
36
36
  within_a_yaml_document_of file, &block
@@ -8,7 +8,6 @@ module Tamiyo
8
8
  class YamlSource
9
9
  include Process::Node
10
10
  include YamlHelper
11
- include DataStore
12
11
 
13
12
  def pull
14
13
  using_object [] do |cards|
@@ -52,7 +51,8 @@ module Tamiyo
52
51
  end
53
52
 
54
53
  def with_the_cards_file
55
- path = provide_path_for 'cards.yaml'
54
+ data_store = DataStore.new
55
+ path = data_store.path_for 'cards.yaml'
56
56
  if block_given?
57
57
  File.open(path, 'r') do |file|
58
58
  yield yaml_event_stream_for file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tamiyo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Norling
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-27 00:00:00.000000000 Z
11
+ date: 2014-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler