widgeo 0.0.2 → 0.0.4

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
- SHA1:
3
- metadata.gz: e2aa0a07dfb5675efc75c797d1e22e17a458af98
4
- data.tar.gz: 61928468ade60db782e26dafc8a25166aabd27e2
2
+ SHA256:
3
+ metadata.gz: 75b0f3149f3e737c6196fcef3d49c3c006c64ba09efeb2ee1470957339d45fdf
4
+ data.tar.gz: 0c5d3ecd23769a697ff07317b39e758ddd27b8beff2bd5f1f3224f2e9619a065
5
5
  SHA512:
6
- metadata.gz: 91f8f6728d144742ae282532f2ea8388bc383b0f26f719e108494b5039aaa0150649e7f6e27ab27a66e8fec96dbd9f9542499d317899b508d2d00823d7f1f5b4
7
- data.tar.gz: 6a4988c7d7b2d54e6768bbd1a2a613ef949a86e86b2d66d683ff07b276eb01280ba95238901ed8e911bb8052eacbe7afb47353c336e9437c9f9ef88ea45900f0
6
+ metadata.gz: a8381e432e2c16b88b37c974039fe9cac523ecf79e2ca853be975cae6296a394e798ab0d6ef25de450119c7ce8fe619e6b3e1492969095a2b27d66814e0a6bf9
7
+ data.tar.gz: d83b75e37671765a5c32c49cda425ee794598a7655ec99dcefcc4a23024ce8f2eb0e3f4a41c9089a671e5348d3da6de8b69f93e0f09d8316c4dc122e885a9984
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Naming/VariableNumber:
7
+ AllowedIdentifiers:
8
+ - alpha_2
9
+ - continent_alpha_2
10
+
11
+ Metrics/BlockLength:
12
+ Max: 35
13
+ Exclude:
14
+ - "spec/**/*"
15
+
16
+ Gemspec/DevelopmentDependencies:
17
+ Enabled: false
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in widgeo.gemspec
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 Chris G
1
+ Copyright (c) 2015 Chris Garrett
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -6,7 +6,7 @@ Widgeo provides easy access to the worlds territories and their continents.
6
6
 
7
7
  Include Widgeo in your Gemfile, `gem "widgeo", require: true` and run `bundle install`.
8
8
 
9
- #### #all
9
+ #### .all
10
10
 
11
11
  Provides a list of all items.
12
12
 
@@ -18,7 +18,15 @@ and all territories:
18
18
 
19
19
  `territories = Widgeo::Territory.all`
20
20
 
21
- #### #find_by
21
+ #### .filter_by
22
+
23
+ Allows for filtering a list of items.
24
+
25
+ For a filtered list of territories in the EU:
26
+
27
+ `territories = Widgeo::Territories.filter_by continent_alpha_2: "EU"`
28
+
29
+ #### .find_by
22
30
 
23
31
  Provides a single item matching a specified property and value.
24
32
 
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "rspec/core/rake_task"
2
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
3
2
 
4
- RSpec::Core::RakeTask.new(:spec) do |task|
5
-
6
- task.rspec_opts = ["--color"]
3
+ require 'rspec/core/rake_task'
4
+ require 'bundler/gem_tasks'
7
5
 
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ task.rspec_opts = ['--color']
8
8
  end
9
9
 
10
- task :default => :spec
10
+ task default: :spec
@@ -1,40 +1,43 @@
1
- module Widgeo
1
+ # frozen_string_literal: true
2
2
 
3
+ module Widgeo
4
+ # Methods for working with collection of entities
3
5
  module Collection
4
-
5
6
  # Set/Get the dataset file name
6
- def dataset_file file_name = nil
7
-
7
+ def dataset_file(file_name = nil)
8
8
  @dataset_file ||= file_name
9
-
10
9
  end
11
10
 
12
11
  # Return the dataset
13
12
  def dataset
14
-
15
13
  # Raise an exception if the dataset file has not been set on the class
16
14
  raise UndefinedDatasetError unless dataset_file
17
15
 
18
16
  @dataset ||= YAML.load_file(
19
- File.join(File.dirname(__FILE__), "../", "data", "#{dataset_file}.yml")
17
+ File.join(File.dirname(__FILE__), '../', 'data', "#{dataset_file}.yml")
20
18
  )
19
+ end
21
20
 
21
+ # Does the item match the requested attributes?
22
+ def matches?(item, attributes)
23
+ attributes.map do |attribute, value|
24
+ item.send(attribute) == value
25
+ end.flatten == [true]
22
26
  end
23
27
 
24
- # Find an item by an attribute
25
- def find_by attribute, value
28
+ # Filter the items by a combination of values
29
+ def filter_by(attributes)
30
+ all.select { |item| matches? item, attributes }
31
+ end
26
32
 
33
+ # Find an item by an attribute
34
+ def find_by(attribute, value)
27
35
  all.detect { |continent| continent.send(attribute) == value }
28
-
29
36
  end
30
37
 
31
38
  # Parse full list and memoize it
32
39
  def all
33
-
34
- @all ||= dataset.map { |item| self.new item }
35
-
40
+ @all ||= dataset.map { |item| new item }
36
41
  end
37
-
38
42
  end
39
-
40
43
  end
@@ -1,14 +1,13 @@
1
- module Widgeo
1
+ # frozen_string_literal: true
2
2
 
3
+ module Widgeo
4
+ # Working with continents
3
5
  class Continent
4
-
5
6
  extend Widgeo::Collection
6
7
  include Widgeo::Model
7
8
 
8
9
  attr_reader :name, :alpha_2
9
10
 
10
11
  dataset_file :continents
11
-
12
12
  end
13
-
14
13
  end
data/lib/widgeo/model.rb CHANGED
@@ -1,21 +1,16 @@
1
- module Widgeo
1
+ # frozen_string_literal: true
2
2
 
3
+ module Widgeo
4
+ # Work with an entity
3
5
  module Model
4
-
5
6
  # Set attributes on the instance
6
- def initialize properties
7
-
8
- properties.each { |name, value|
9
-
7
+ def initialize(properties)
8
+ properties.each do |name, value|
10
9
  # Raise an exception if we don't have a getter for the property
11
10
  raise UndefinedFieldError unless respond_to? name
12
11
 
13
- instance_variable_set("@#{name}", value)
14
-
15
- }
16
-
12
+ instance_variable_set(:"@#{name}", value)
13
+ end
17
14
  end
18
-
19
15
  end
20
-
21
16
  end
@@ -1,7 +1,8 @@
1
- module Widgeo
1
+ # frozen_string_literal: true
2
2
 
3
+ module Widgeo
4
+ # Working with territories
3
5
  class Territory
4
-
5
6
  extend Widgeo::Collection
6
7
  include Widgeo::Model
7
8
 
@@ -11,11 +12,7 @@ module Widgeo
11
12
 
12
13
  # Load an instance of the continent
13
14
  def continent
14
-
15
15
  Continent.find_by :alpha_2, continent_alpha_2
16
-
17
16
  end
18
-
19
17
  end
20
-
21
18
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Widgeo
2
- VERSION = "0.0.2"
4
+ VERSION = '0.0.4'
3
5
  end
data/lib/widgeo.rb CHANGED
@@ -1,14 +1,15 @@
1
- require "widgeo/version"
2
- require "widgeo/collection"
3
- require "widgeo/model"
4
- require "widgeo/continent"
5
- require "widgeo/territory"
1
+ # frozen_string_literal: true
6
2
 
7
- module Widgeo
3
+ require 'widgeo/version'
4
+ require 'widgeo/collection'
5
+ require 'widgeo/model'
6
+ require 'widgeo/continent'
7
+ require 'widgeo/territory'
8
8
 
9
- require "yaml"
9
+ # Provides territory and continent utilities for ruby
10
+ module Widgeo
11
+ require 'yaml'
10
12
 
11
13
  class UndefinedDatasetError < StandardError; end
12
14
  class UndefinedFieldError < StandardError; end
13
-
14
15
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,3 @@
1
- require "widgeo"
1
+ # frozen_string_literal: true
2
+
3
+ require 'widgeo'
@@ -1,42 +1,36 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe Widgeo::Continent do
3
+ require 'spec_helper'
4
4
 
5
- CONTINENT_COUNT = 7
6
- INVALID_CONTINENT = { bad_field: "BAD FIELD" }
7
- CONTINENT_ALPHA = "EU"
8
- VALID_CONTINENT = { name: "Beatland", alpha_2: "BE" }
9
- CONTINENT_FIELDS = [:name, :alpha_2]
5
+ CONTINENT_COUNT = 7
6
+ INVALID_CONTINENT = { bad_field: 'BAD FIELD' }.freeze
7
+ CONTINENT_ALPHA = 'EU'
8
+ VALID_CONTINENT = { name: 'Beatland', alpha_2: 'BE' }.freeze
9
+ CONTINENT_FIELDS = %i[name alpha_2].freeze
10
10
 
11
+ describe Widgeo::Continent do
11
12
  subject { Widgeo::Continent.new VALID_CONTINENT }
12
13
 
13
- it { is_expected.to respond_to *CONTINENT_FIELDS }
14
-
15
- context "given an invalid dataset" do
16
-
17
- subject { -> { Widgeo::Continent.new INVALID_CONTINENT } }
18
-
19
- it { is_expected.to raise_error Widgeo::UndefinedFieldError }
14
+ it { is_expected.to respond_to(*CONTINENT_FIELDS) }
20
15
 
16
+ context 'given an invalid dataset' do
17
+ it 'raises UndefinedFieldError' do
18
+ expect { Widgeo::Continent.new INVALID_CONTINENT }.to raise_error Widgeo::UndefinedFieldError
19
+ end
21
20
  end
22
21
 
23
- describe ".find_by" do
24
-
22
+ describe '.find_by' do
25
23
  subject(:continent) { Widgeo::Continent.find_by :alpha_2, CONTINENT_ALPHA }
26
24
 
27
25
  it { expect(continent).to be_kind_of Widgeo::Continent }
28
26
  it { expect(continent.alpha_2).to eq CONTINENT_ALPHA }
29
-
30
27
  end
31
28
 
32
- describe ".all" do
33
-
29
+ describe '.all' do
34
30
  subject(:continents) { Widgeo::Continent.all }
35
31
 
36
32
  it { expect(continents).to be_kind_of Array }
37
33
  it { expect(continents.size).to be CONTINENT_COUNT }
38
34
  it { expect(continents.first).to be_kind_of Widgeo::Continent }
39
-
40
35
  end
41
-
42
36
  end
@@ -1,59 +1,62 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe Widgeo::Territory do
3
+ require 'spec_helper'
4
4
 
5
- TERRITORY_COUNT = 254
6
- INVALID_TERRITORY = { bad_field: "BAD FIELD" }
7
- TERRITORY_ALPHA = "GB"
8
- PARENT_CONTINENT_ALPHA = "EU"
5
+ TERRITORY_COUNT = 254
6
+ INVALID_TERRITORY = { bad_field: 'BAD FIELD' }.freeze
7
+ TERRITORY_ALPHA = 'GB'
8
+ EU_TERRITORY_COUNT = 50
9
+ PARENT_CONTINENT_ALPHA = 'EU'
9
10
 
10
- VALID_TERRITORY = {
11
- name: "Beatland", long_name: "Peoples republic of Beatland",
12
- alpha_2: "BE", continent_alpha_2: "EU"
13
- }
11
+ VALID_TERRITORY = {
12
+ name: 'Beatland', long_name: 'Peoples republic of Beatland',
13
+ alpha_2: 'BE', continent_alpha_2: 'EU'
14
+ }.freeze
14
15
 
15
- TERRITORY_FIELDS = [:name, :long_name, :alpha_2, :continent_alpha_2]
16
+ TERRITORY_FIELDS = %i[name long_name alpha_2 continent_alpha_2].freeze
16
17
 
18
+ describe Widgeo::Territory do
17
19
  subject { Widgeo::Territory.new VALID_TERRITORY }
18
20
 
19
- it { is_expected.to respond_to *TERRITORY_FIELDS }
20
-
21
- context "given an invalid dataset" do
22
-
23
- subject { -> { Widgeo::Territory.new INVALID_TERRITORY } }
24
-
25
- it { is_expected.to raise_error Widgeo::UndefinedFieldError }
21
+ it { is_expected.to respond_to(*TERRITORY_FIELDS) }
26
22
 
23
+ context 'given an invalid dataset' do
24
+ it 'raises UndefinedFieldError' do
25
+ expect { Widgeo::Territory.new INVALID_TERRITORY }.to raise_error Widgeo::UndefinedFieldError
26
+ end
27
27
  end
28
28
 
29
- describe "#continent" do
30
-
31
- subject (:continent) {
29
+ describe '#continent' do
30
+ subject(:continent) do
32
31
  Widgeo::Territory.find_by(:alpha_2, TERRITORY_ALPHA).continent
33
- }
32
+ end
34
33
 
35
34
  it { expect(continent).to be_kind_of Widgeo::Continent }
36
35
  it { expect(continent.alpha_2).to eq PARENT_CONTINENT_ALPHA }
37
-
38
36
  end
39
37
 
40
- describe ".find_by" do
41
-
38
+ describe '.find_by' do
42
39
  subject(:territory) { Widgeo::Territory.find_by :alpha_2, TERRITORY_ALPHA }
43
40
 
44
41
  it { expect(territory).to be_kind_of Widgeo::Territory }
45
42
  it { expect(territory.alpha_2).to eq TERRITORY_ALPHA }
46
-
47
43
  end
48
44
 
49
- describe ".all" do
45
+ describe '.filter_by' do
46
+ subject(:territories) do
47
+ Widgeo::Territory.filter_by continent_alpha_2: PARENT_CONTINENT_ALPHA
48
+ end
49
+
50
+ it { expect(territories).to be_kind_of Array }
51
+ it { expect(territories.size).to be EU_TERRITORY_COUNT }
52
+ it { expect(territories.first).to be_kind_of Widgeo::Territory }
53
+ end
50
54
 
55
+ describe '.all' do
51
56
  subject(:territories) { Widgeo::Territory.all }
52
57
 
53
- it { expect(territories).to be_kind_of Array }
58
+ it { expect(territories).to be_a_kind_of(Array) }
54
59
  it { expect(territories.size).to be TERRITORY_COUNT }
55
60
  it { expect(territories.first).to be_kind_of Widgeo::Territory }
56
-
57
61
  end
58
-
59
62
  end
data/widgeo.gemspec CHANGED
@@ -1,27 +1,31 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'widgeo/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
8
+ spec.required_ruby_version = '>= 2.7.0'
9
+ spec.name = 'widgeo'
10
+ spec.version = Widgeo::VERSION
11
+ spec.authors = ['Chris Garrett']
12
+ spec.email = ['chris@hyperlaunch.com']
13
+ spec.summary = 'Provides easy access to the worlds territories and their continents.'
14
+ spec.description = 'Listing and filtering of continents and territories. ' \
15
+ 'Includes short names, long names and alpha codes, ' \
16
+ 'following the ISO 3166 standard.'
7
17
 
8
- spec.name = "widgeo"
9
- spec.version = Widgeo::VERSION
10
- spec.authors = ["Chris G"]
11
- spec.email = ["chris@abstraktion.co.uk"]
12
- spec.summary = "Provides easy access to the worlds territories and their continents."
13
- spec.description = "Listing and filtering of continents and territories. Includes short names, long names and alpha codes, following the ISO 3166 standard."
14
- spec.homepage = "https://github.com/BeatrootApp/Widgeo"
15
- spec.license = "MIT"
16
-
17
- spec.files = `git ls-files -z`.split("\x0")
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_development_dependency "bundler", "~> 1.7"
23
- spec.add_development_dependency "rake", "~> 10.0"
18
+ spec.homepage = 'https://github.com/hyperlaunch/widgeo'
19
+ spec.license = 'MIT'
24
20
 
25
- spec.add_development_dependency "rspec", "~> 3.1"
21
+ spec.files = `git ls-files -z`.split("\x0")
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
26
24
 
25
+ spec.add_development_dependency 'bundler', '~> 2.0'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.1'
28
+ spec.add_development_dependency 'rubocop', '~> 1.67'
29
+ spec.add_development_dependency 'ruby-lsp', '~> 0.20.1'
30
+ spec.metadata['rubygems_mfa_required'] = 'true'
27
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: widgeo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
- - Chris G
8
- autorequire:
7
+ - Chris Garrett
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-24 00:00:00.000000000 Z
11
+ date: 2024-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,15 +52,44 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.67'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.67'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-lsp
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.20.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.20.1
55
83
  description: Listing and filtering of continents and territories. Includes short names,
56
84
  long names and alpha codes, following the ISO 3166 standard.
57
85
  email:
58
- - chris@abstraktion.co.uk
86
+ - chris@hyperlaunch.com
59
87
  executables: []
60
88
  extensions: []
61
89
  extra_rdoc_files: []
62
90
  files:
63
91
  - ".gitignore"
92
+ - ".rubocop.yml"
64
93
  - Gemfile
65
94
  - LICENSE.txt
66
95
  - README.md
@@ -77,11 +106,12 @@ files:
77
106
  - spec/widgeo/continent_spec.rb
78
107
  - spec/widgeo/territory_spec.rb
79
108
  - widgeo.gemspec
80
- homepage: https://github.com/BeatrootApp/Widgeo
109
+ homepage: https://github.com/hyperlaunch/widgeo
81
110
  licenses:
82
111
  - MIT
83
- metadata: {}
84
- post_install_message:
112
+ metadata:
113
+ rubygems_mfa_required: 'true'
114
+ post_install_message:
85
115
  rdoc_options: []
86
116
  require_paths:
87
117
  - lib
@@ -89,19 +119,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
119
  requirements:
90
120
  - - ">="
91
121
  - !ruby/object:Gem::Version
92
- version: '0'
122
+ version: 2.7.0
93
123
  required_rubygems_version: !ruby/object:Gem::Requirement
94
124
  requirements:
95
125
  - - ">="
96
126
  - !ruby/object:Gem::Version
97
127
  version: '0'
98
128
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.2.2
101
- signing_key:
129
+ rubygems_version: 3.5.16
130
+ signing_key:
102
131
  specification_version: 4
103
132
  summary: Provides easy access to the worlds territories and their continents.
104
- test_files:
105
- - spec/spec_helper.rb
106
- - spec/widgeo/continent_spec.rb
107
- - spec/widgeo/territory_spec.rb
133
+ test_files: []