gmt 0.0.9 → 0.0.10

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/ext/gmt/option.c +10 -2
  3. data/lib/gmt.rb +44 -42
  4. metadata +5 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fa6455137a875453333acb344af988d06610a9c
4
- data.tar.gz: b06416fe648fda0fa83d1d8d8a2b38c2fb3e41a9
3
+ metadata.gz: 83004af94b065d8ed5dcc96880f9f92eb24d9587
4
+ data.tar.gz: c3c3b8a34eecbe5d65fdd434a9d79ed4fe3a2ebf
5
5
  SHA512:
6
- metadata.gz: 95eba465b3606499f9200fbcd41e5d5426282a5a9436eea512e5b71a4f7abdc23806fc9c12e647283aad032394d27379bbbee01ddfc672212af57c7ce7fa73a2
7
- data.tar.gz: 4f4149ed3eb0b7e80c149d140cbdbb568e8edebde42e837a85512e178bae1858a205d7c7f72b423c0030711bab0dca650a50f28d29ab8fe5262df4be8abe2ad6
6
+ metadata.gz: 203784ecd104c0412a2c327c10457c1508754574e9a5dfb6224cf708ef8f438e4460b1a2118e76f49d0f63cb5378949aacfab5074e9800e5070357f9818fe1f1
7
+ data.tar.gz: db221c721995a317e2dc78eb0e18247dc58c78006769715ded65aaea10ca96e24a5a7c1ecfffb86133983d3df027686f4997a007d4134515207e068af3375663
data/ext/gmt/option.c CHANGED
@@ -2,8 +2,8 @@
2
2
  option.c
3
3
 
4
4
  GMT expects arguments to be in a linked-list format and provides
5
- some library support for creating these. We here convert a hash
6
- to this linked-list format.
5
+ some library support for creating these. We here convert a Ruby
6
+ array-of-pairs to this linked-list format.
7
7
  */
8
8
 
9
9
  #include "option.h"
@@ -42,14 +42,18 @@ extern gmt_option_t* ruby_array_to_gmt_options(VALUE opts, void *session)
42
42
  for (size_t i = 0 ; i < RARRAY_LEN(opts) ; i++)
43
43
  {
44
44
  VALUE opt = RARRAY_PTR(opts)[i];
45
+
45
46
  if (TYPE(opt) != T_ARRAY)
46
47
  rb_raise(rb_eArgError, "each option should be a array");
47
48
  if (RARRAY_LEN(opt) != 2)
48
49
  rb_raise(rb_eArgError, "each option should be a pair");
50
+
49
51
  VALUE key = RARRAY_PTR(opt)[0];
50
52
  char option_name = char_of_key(key);
53
+
51
54
  VALUE arg = RARRAY_PTR(opt)[1];
52
55
  const char *option_arg;
56
+
53
57
  switch (TYPE(arg))
54
58
  {
55
59
  case T_STRING:
@@ -63,6 +67,7 @@ extern gmt_option_t* ruby_array_to_gmt_options(VALUE opts, void *session)
63
67
  default:
64
68
  rb_raise(rb_eArgError, "option argument should be string or nil");
65
69
  }
70
+
66
71
  gmt_opts = append_option(session, option_name, option_arg, gmt_opts);
67
72
  }
68
73
 
@@ -79,9 +84,12 @@ extern gmt_option_t* append_inputs_to_gmt_options(VALUE files,
79
84
  for (size_t i = 0 ; i < RARRAY_LEN(files) ; i++)
80
85
  {
81
86
  VALUE file = RARRAY_PTR(files)[i];
87
+
82
88
  if (TYPE(file) != T_STRING)
83
89
  rb_raise(rb_eArgError, "each input should be a string");
90
+
84
91
  const char *option_arg = StringValueCStr(file);
92
+
85
93
  gmt_opts = append_option(session, '<', option_arg, gmt_opts);
86
94
  }
87
95
 
data/lib/gmt.rb CHANGED
@@ -99,11 +99,10 @@ class GMT
99
99
  # @see http://gmt.soest.hawaii.edu/doc/latest/$1.html
100
100
  def wrapper_ps(method)
101
101
  define_method(method) do |*args, options|
102
- options = postscript_options(options)
103
- fix_append_option!(options)
104
- self.send(api_function(method),
105
- *string_arguments(args),
106
- array_options(options))
102
+ coerce_string_arguments!(args)
103
+ coerce_postscript_options!(options)
104
+ coerce_append_option!(options)
105
+ self.send(api_function(method), *args, options_as_pairs(options))
107
106
  end
108
107
  end
109
108
 
@@ -115,10 +114,9 @@ class GMT
115
114
  # @see http://gmt.soest.hawaii.edu/doc/latest/$1.html
116
115
  def wrapper_other(method)
117
116
  define_method(method) do |*args, options|
118
- fix_append_option!(options)
119
- self.send(api_function(method),
120
- *string_arguments(args),
121
- array_options(options))
117
+ coerce_string_arguments!(args)
118
+ coerce_append_option!(options)
119
+ self.send(api_function(method), *args, options_as_pairs(options))
122
120
  end
123
121
  end
124
122
 
@@ -132,62 +130,66 @@ class GMT
132
130
  [method.to_s, 'c'].join('_').to_sym
133
131
  end
134
132
 
135
- # convert non-option arguments to strings
133
+ # convert arguments to strings
136
134
 
137
- def string_arguments(args)
138
- args.map(&:to_s)
135
+ def coerce_string_arguments!(arguments)
136
+ arguments.map!(&:to_s)
137
+ end
138
+
139
+ # for GMT modules which produce PostScript, convert the
140
+ # convenience options (:position, :file) to the hash
141
+ # equivalent of the -K, -O options, and the creation of
142
+ # or appending to the PostScript output file
143
+
144
+ def coerce_postscript_options!(options)
145
+ file = options.delete(:file)
146
+ position = options.delete(:position)
147
+ if file && position then
148
+ file_options =
149
+ case position
150
+ when :first, 'first'
151
+ { :K => nil, :> => file }
152
+ when :middle, 'middle'
153
+ { :O => nil, :K => nil, :>> => file }
154
+ when :last, 'last'
155
+ { :O => nil, :>> => file }
156
+ else
157
+ raise ArgumentError, 'position should be :first, :middle or :last'
158
+ end
159
+ options.merge!(file_options)
160
+ end
139
161
  end
140
162
 
141
163
  # handle the :>> option
142
164
 
143
- def fix_append_option!(options)
165
+ def coerce_append_option!(options)
144
166
  if file = options.delete(:>>) then
145
167
  options[:>] = '>' + file
146
168
  end
147
169
  end
148
170
 
171
+ # convert non-nil argument to string
172
+
173
+ def string_unless_nil(argument)
174
+ argument.to_s unless argument.nil?
175
+ end
176
+
149
177
  # convert the options hash to an array of pairs
150
178
 
151
- def array_options(options)
179
+ def options_as_pairs(options)
152
180
  options.inject(Array.new) do |result, pair|
153
181
  key, values = pair
154
182
  if values.respond_to? :each then
155
183
  values.each do |value|
156
- result << [key, value]
184
+ result << [key, string_unless_nil(value)]
157
185
  end
158
186
  else
159
- result << [key, values]
187
+ result << [key, string_unless_nil(values)]
160
188
  end
161
189
  result
162
190
  end
163
191
  end
164
192
 
165
- # for GMT modules which produce PostScript, convert the
166
- # convenience options (:position, :file) to the hash
167
- # equivalent of the -K, -O options, and the creation of
168
- # or appending to the PostScript output file
169
-
170
- def postscript_options(options)
171
- file = options.delete(:file)
172
- position = options.delete(:position)
173
- if file && position then
174
- file_options =
175
- case position
176
- when :first
177
- { :K => nil, :> => file }
178
- when :middle
179
- { :O => nil, :K => nil, :>> => file }
180
- when :last
181
- { :O => nil, :>> => file }
182
- else
183
- raise ArguemntError, 'position should be :first, :middle or :last'
184
- end
185
- options.merge(file_options)
186
- else
187
- options
188
- end
189
- end
190
-
191
193
  public
192
194
 
193
195
  # @!group Filtering of 1-D and 2-D Data
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - J.J. Green
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-05 00:00:00.000000000 Z
11
+ date: 2016-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,10 +67,8 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.8'
69
69
  description: |
70
- A Ruby extension for the Generic Mapping Tools (GMT)
70
+ A Ruby extension for the Generic Mapping Tools (GMT5)
71
71
  cartographic toolset (work-in-progress).
72
-
73
- Requires the GMT5 development libraries.
74
72
  email: j.j.green@gmx.co.uk
75
73
  executables: []
76
74
  extensions:
@@ -102,7 +100,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
100
  - !ruby/object:Gem::Version
103
101
  version: '0'
104
102
  requirements:
105
- - ghostscript (gs) for the test-suite
103
+ - GMT5 development libraries
104
+ - ghostscript (for tests)
106
105
  rubyforge_project:
107
106
  rubygems_version: 2.2.2
108
107
  signing_key: