gias 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 56a60c305e47e9ce483de28e2adff99f2be17b3ff29f6492ef2a6a2a128b094f
4
+ data.tar.gz: ddc996e48c7f70279d1756f64f394dfee9c16ff2bf7ef4cc8a6ced0f0ec0a837
5
+ SHA512:
6
+ metadata.gz: 97764ba8f3aae8f94b288303f98a7a8196abaa69814ac032f5da9cb035f99b261f13fcb50ce04764eafef222f04e4737be9dc51b6e6303277459672895a19bc2
7
+ data.tar.gz: 8ead345d18001cede065a2f7f7a0ccfe947fb63ee5707765a14fa505c7ca1c5593dd4fcbaa5b0f532f4cd534bf0f4fc8e44119ec95bd503ab53bae8adf0007cb
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Daniel Dye
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Get-Information-About-Schools (GIAS) Ruby Gem
2
+
3
+ This gem provides a Ruby interface to the Department for Education's Get Information About Schools (GIAS) CSV.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "gias"
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ To get the list of all schools:
16
+
17
+ ```ruby
18
+ Gias::School.all
19
+ ```
20
+
21
+ This will:
22
+
23
+ - Download the latest CSV from the DfE's website.
24
+ - Convert the CSV to an array of `Gias::School` objects.
25
+
26
+ The attribute names are the CSV column names, without parentheses, converted to snake_case.
27
+
28
+ For example:
29
+
30
+ ```ruby
31
+ {
32
+ "LA (code)" => :la_code,
33
+ "PhaseOfEducation (name)" => :phase_of_education_name,
34
+ }
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Nitemaeric/gias.
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/gias.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/gias/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "gias"
7
+ spec.version = Gias::VERSION
8
+ spec.authors = ["Daniel Dye"]
9
+ spec.email = ["dnitemaeric@gmail.com"]
10
+
11
+ spec.summary = "A Ruby gem that provides an interface to the Get Information About Schools (GIAS) CSV data."
12
+ spec.description = "A Ruby gem that provides an interface to the Get Information About Schools (GIAS) CSV data."
13
+ # spec.homepage = "TODO: Put your gem's website or public repo URL here."
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ # spec.metadata["homepage_uri"] = spec.homepage
20
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) ||
28
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
29
+ end
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ # Uncomment to register a new dependency of your gem
36
+ spec.add_dependency "activesupport", "~> 7.1.3.2"
37
+
38
+ # For more information and examples about making a new gem, check out our
39
+ # guide at: https://bundler.io/guides/creating_gem.html
40
+ end
@@ -0,0 +1,65 @@
1
+ require "open-uri"
2
+ require "csv"
3
+ require "active_support/all"
4
+
5
+ module Gias
6
+ class School
7
+ HOST = "https://ea-edubase-api-prod.azurewebsites.net"
8
+
9
+ attr_reader :attributes
10
+
11
+ def initialize(attributes = {})
12
+ @attributes = attributes
13
+ end
14
+
15
+ def inspect
16
+ "#<#{self.class.name} #{attributes.map { |k, v| "#{k}: #{v.inspect}"}.join(", ")}>"
17
+ end
18
+
19
+ def method_missing(method_name, *args, &block)
20
+ if attribute_names.include?(method_name.to_s)
21
+ @attributes[method_name.to_s]
22
+ else
23
+ super
24
+ end
25
+ end
26
+
27
+ def respond_to_missing?(method_name, include_private = false)
28
+ attribute_names.include?(method_name.to_s) || super
29
+ end
30
+
31
+ def attribute_names
32
+ self.class.attribute_names
33
+ end
34
+
35
+ class << self
36
+ delegate :first, :last, :size, :count, :length, to: :all
37
+
38
+ def all
39
+ @all ||= csv.map do |row|
40
+ new(row.to_h.transform_keys { convert_header(_1) })
41
+ end
42
+ end
43
+
44
+ def csv
45
+ @csv ||= CSV.parse(csv_data, headers: true, empty_value: nil)
46
+ end
47
+
48
+ def csv_data
49
+ hash = Hash.new do |h, k|
50
+ h[k] = URI.open(HOST + "/edubase/downloads/public/edubasealldata#{k}.csv")
51
+ end
52
+
53
+ hash[Date.current.strftime("%Y%m%d")]
54
+ end
55
+
56
+ def attribute_names
57
+ @headers ||= csv.headers.map { convert_header(_1) }
58
+ end
59
+
60
+ def convert_header(header)
61
+ header.gsub("(", "").gsub(")", "").gsub(" ", "_").underscore
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gias
4
+ VERSION = "0.1.0"
5
+ end
data/lib/gias.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "gias/version"
4
+ require_relative "gias/school"
5
+
6
+ module Gias
7
+ class Error < StandardError; end
8
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gias
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Dye
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-04-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 7.1.3.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 7.1.3.2
27
+ description: A Ruby gem that provides an interface to the Get Information About Schools
28
+ (GIAS) CSV data.
29
+ email:
30
+ - dnitemaeric@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - gias.gemspec
41
+ - lib/gias.rb
42
+ - lib/gias/school.rb
43
+ - lib/gias/version.rb
44
+ homepage:
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.6.0
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.4.10
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: A Ruby gem that provides an interface to the Get Information About Schools
67
+ (GIAS) CSV data.
68
+ test_files: []