cartographie 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,8 +20,23 @@ Cartographie.map('San Francisco, CA')
20
20
  Cartographie.map('New York, NY', width: 200, height: 200, zoom: 10)
21
21
  ```
22
22
 
23
+ **Configuration**
24
+
25
+ ```ruby
26
+ Cartographie.configure do |config|
27
+ config.width = 640
28
+ config.height = 640
29
+ config.zoom = 12
30
+ config.file_format = 'jpg'
31
+ config.sensor = true
32
+ end
33
+ ```
34
+
23
35
  **Defaults**
24
36
 
37
+ If you do not pass options when generating a map, nor configure a map attribute
38
+ using the configuration block, the following values will be used:
39
+
25
40
  - width: 300
26
41
  - height: 300
27
42
  - zoom: 15
data/lib/cartographie.rb CHANGED
@@ -3,6 +3,7 @@ require "cartographie/version"
3
3
  # Cartographie is the root module for all of Cartographie's components
4
4
  module Cartographie
5
5
 
6
+ autoload :Config, 'cartographie/config'
6
7
  autoload :Map, 'cartographie/map'
7
8
 
8
9
  # Public: Create a new Map instance.
@@ -25,4 +26,8 @@ module Cartographie
25
26
  Map.new(location, options)
26
27
  end
27
28
 
29
+ def self.configure(&block)
30
+ Cartographie::Config.configure(&block)
31
+ end
32
+
28
33
  end
@@ -0,0 +1,65 @@
1
+ module Cartographie
2
+ module Config
3
+ extend self
4
+
5
+ def configure
6
+ yield self
7
+ end
8
+
9
+ def api_endpoint
10
+ OPTIONS[:api_endpoint]
11
+ end
12
+
13
+ def width
14
+ OPTIONS[:width]
15
+ end
16
+
17
+ def width=(value)
18
+ OPTIONS[:width] = value
19
+ end
20
+
21
+ def height
22
+ OPTIONS[:height]
23
+ end
24
+
25
+ def height=(value)
26
+ OPTIONS[:height] = value
27
+ end
28
+
29
+ def zoom
30
+ OPTIONS[:zoom]
31
+ end
32
+
33
+ def zoom=(value)
34
+ OPTIONS[:zoom] = value
35
+ end
36
+
37
+ def file_format
38
+ OPTIONS[:file_format]
39
+ end
40
+
41
+ def file_format=(value)
42
+ OPTIONS[:file_format] = value
43
+ end
44
+
45
+ def sensor
46
+ OPTIONS[:sensor]
47
+ end
48
+
49
+ def sensor=(value)
50
+ OPTIONS[:sensor] = value
51
+ end
52
+
53
+ private
54
+
55
+ DEFAULTS = {
56
+ api_endpoint: 'http://maps.googleapis.com/maps/api/staticmap',
57
+ width: 300,
58
+ height: 300,
59
+ zoom: 15,
60
+ file_format: 'png',
61
+ sensor: false
62
+ }
63
+ OPTIONS = {}.merge!(DEFAULTS)
64
+ end
65
+ end
@@ -11,13 +11,6 @@ module Cartographie
11
11
  # Public: Gets/Sets the Hash options for the map.
12
12
  attr_accessor :options
13
13
 
14
- API_ENDPOINT = 'http://maps.googleapis.com/maps/api/staticmap'
15
- DEFAULT_WIDTH = 300
16
- DEFAULT_HEIGHT = 300
17
- DEFAULT_ZOOM = 15
18
- DEFAULT_FILE_FORMAT = 'png'
19
- DEFAULT_SENSOR = false
20
-
21
14
  # Public: Initialize a Map
22
15
  #
23
16
  # location - The String for the map's location (default: 'Paris, France').
@@ -55,27 +48,27 @@ module Cartographie
55
48
 
56
49
  # Returns the Integer width passed in options, or default
57
50
  def width
58
- options[:width] || DEFAULT_WIDTH
51
+ options[:width] || Config.width
59
52
  end
60
53
 
61
54
  # Returns the Integer height passed in options, or default
62
55
  def height
63
- options[:height] || DEFAULT_HEIGHT
56
+ options[:height] || Config.height
64
57
  end
65
58
 
66
59
  # Returns the Integer zoom level passed in options, or default
67
60
  def zoom
68
- options[:zoom] || DEFAULT_ZOOM
61
+ options[:zoom] || Config.zoom
69
62
  end
70
63
 
71
64
  # Returns the String file format passed in options, or default
72
65
  def file_format
73
- options[:file_format] || DEFAULT_FILE_FORMAT
66
+ options[:file_format] || Config.file_format
74
67
  end
75
68
 
76
69
  # Returns the Boolean indicating sensor usage passed in options, or default
77
70
  def sensor
78
- options[:sensor] || DEFAULT_SENSOR
71
+ options[:sensor] || Config.sensor
79
72
  end
80
73
 
81
74
  # Returns a string combining width and height into dimensions
@@ -86,7 +79,7 @@ module Cartographie
86
79
  private
87
80
 
88
81
  def api_endpoint
89
- API_ENDPOINT
82
+ Config.api_endpoint
90
83
  end
91
84
  end
92
85
  end
@@ -1,3 +1,3 @@
1
1
  module Cartographie
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'cartographie'
3
+ require 'cartographie/config'
4
+
5
+ describe Cartographie::Config do
6
+ subject { Cartographie::Config }
7
+
8
+ describe "default configs" do
9
+ its(:api_endpoint) { should eq('http://maps.googleapis.com/maps/api/staticmap') }
10
+ its(:width) { should eq(300) }
11
+ its(:height) { should eq(300) }
12
+ its(:zoom) { should eq(15) }
13
+ its(:file_format) { should eq('png') }
14
+ its(:sensor) { should be_false }
15
+ end
16
+
17
+ describe "setting new defaults" do
18
+ before do
19
+ Cartographie.configure do |config|
20
+ config.width = 100
21
+ config.height = 100
22
+ config.zoom = 10
23
+ config.file_format = 'jpg'
24
+ config.sensor = true
25
+ end
26
+ end
27
+
28
+ its(:width) { should eq(100) }
29
+ its(:height) { should eq(100) }
30
+ its(:zoom) { should eq(10) }
31
+ its(:file_format) { should eq('jpg') }
32
+ its(:sensor) { should be_true }
33
+ end
34
+ end
@@ -5,16 +5,6 @@ describe Cartographie::Map do
5
5
 
6
6
  subject { described_class.new }
7
7
 
8
- describe 'defaults' do
9
- its(:location) { should eq('Paris, France') }
10
- its(:width) { should eq(300) }
11
- its(:height) { should eq(300) }
12
- its(:size) { should eq('300x300') }
13
- its(:zoom) { should eq(15) }
14
- its(:file_format) { should eq('png') }
15
- its(:sensor) { should be_false }
16
- end
17
-
18
8
  describe 'with options' do
19
9
  let(:options) do
20
10
  { width: 75, height: 75, zoom: 10, file_format: 'jpg', sensor: true }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cartographie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-07-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
16
- requirement: &70348616677260 !ruby/object:Gem::Requirement
16
+ requirement: &70210921610020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70348616677260
24
+ version_requirements: *70210921610020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70348616676800 !ruby/object:Gem::Requirement
27
+ requirement: &70210921609580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70348616676800
35
+ version_requirements: *70210921609580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70348616676220 !ruby/object:Gem::Requirement
38
+ requirement: &70210921609000 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '2.11'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70348616676220
46
+ version_requirements: *70210921609000
47
47
  description: Beautiful map generation
48
48
  email:
49
49
  - mattonrails@shortmail.com
@@ -60,8 +60,10 @@ files:
60
60
  - Rakefile
61
61
  - cartographie.gemspec
62
62
  - lib/cartographie.rb
63
+ - lib/cartographie/config.rb
63
64
  - lib/cartographie/map.rb
64
65
  - lib/cartographie/version.rb
66
+ - spec/cartographie/config_spec.rb
65
67
  - spec/cartographie/map_spec.rb
66
68
  - spec/cartographie_spec.rb
67
69
  - spec/spec_helper.rb
@@ -90,6 +92,7 @@ signing_key:
90
92
  specification_version: 3
91
93
  summary: Wrapper for Google's Static Maps API
92
94
  test_files:
95
+ - spec/cartographie/config_spec.rb
93
96
  - spec/cartographie/map_spec.rb
94
97
  - spec/cartographie_spec.rb
95
98
  - spec/spec_helper.rb