aetheryte 0.0.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: ef32af3ab83c5a9bb1ae6e071566476537d666e84fe17852e804ba6a50ea557f
4
+ data.tar.gz: 5f4df0680c063c8d12be495d8289c37c0edd6d244d2825d57b1bfa204bcd7f52
5
+ SHA512:
6
+ metadata.gz: df37e9cec975cd0290b63ac69616606b69e35ca86983f51a6050f73a713542424a4414eb29ebebe23b5930f12e0cf6a81fc94709678cae033fa21a535599c1e4
7
+ data.tar.gz: 7f6f0bcb781f971cc0c257f1cc0dd6a0ff04a4dd6bdbad653b783fef0f1726db757196bc2c5592f9954a7d7ea0b33f48135972194c740e6b5eaef893a1f56ae7
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gemspec
5
+
6
+ gem 'nokogiri'
7
+
8
+ group :development, :test do
9
+ gem 'pry-byebug'
10
+ gem 'rubocop', require: false
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ aetheryte (0.0.0)
5
+ nokogiri (~> 1.16)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ byebug (11.1.3)
12
+ coderay (1.1.3)
13
+ json (2.6.2)
14
+ method_source (1.0.0)
15
+ nokogiri (1.16.0-arm64-darwin)
16
+ racc (~> 1.4)
17
+ parallel (1.22.1)
18
+ parser (3.1.2.1)
19
+ ast (~> 2.4.1)
20
+ pry (0.14.1)
21
+ coderay (~> 1.1)
22
+ method_source (~> 1.0)
23
+ pry-byebug (3.10.1)
24
+ byebug (~> 11.0)
25
+ pry (>= 0.13, < 0.15)
26
+ racc (1.7.3)
27
+ rainbow (3.1.1)
28
+ regexp_parser (2.8.3)
29
+ rexml (3.2.6)
30
+ rubocop (1.36.0)
31
+ json (~> 2.3)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.1.2.1)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml (>= 3.2.5, < 4.0)
37
+ rubocop-ast (>= 1.20.1, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 1.4.0, < 3.0)
40
+ rubocop-ast (1.21.0)
41
+ parser (>= 3.1.1.0)
42
+ ruby-progressbar (1.11.0)
43
+ unicode-display_width (2.5.0)
44
+
45
+ PLATFORMS
46
+ arm64-darwin-20
47
+
48
+ DEPENDENCIES
49
+ aetheryte!
50
+ nokogiri
51
+ pry-byebug
52
+ rubocop
53
+
54
+ BUNDLED WITH
55
+ 2.3.22
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 tengille
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/aetheryte.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('../lib', __dir__)
4
+ require_relative 'lib/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'aetheryte'
8
+ s.version = Aetheryte::VERSION
9
+ s.summary = 'Aetheryte'
10
+ s.authors = ['tengille']
11
+ s.email = 'melitengille@gmail.com'
12
+ s.license = 'MIT'
13
+ s.homepage = 'https://github.com/tengille/aetheryte'
14
+ s.metadata = { 'rubygems_mfa_required' => 'true' }
15
+
16
+ s.files = Dir['./**/**']
17
+
18
+ s.add_dependency 'nokogiri', '~> 1.16'
19
+ s.add_development_dependency 'pry-byebug', '~> 3.10'
20
+
21
+ s.required_ruby_version = '>= 3.1.1'
22
+
23
+ s.require_paths = ['lib']
24
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aetheryte
4
+ # Object for storing character information
5
+ class Character
6
+ attr_reader :id,
7
+ :race,
8
+ :clan,
9
+ :gender,
10
+ :city_state,
11
+ :grand_company,
12
+ :grand_company_rank,
13
+ :profile
14
+
15
+ def initialize(**args)
16
+ args.each do |name, value|
17
+ instance_variable_set("@#{name}", value)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aetheryte
4
+ # Parses Lodestone character profile
5
+ class ChracterParser
6
+ def initialize(doc:, id:)
7
+ @id = id
8
+ @doc = doc
9
+ @basic_info = doc.css('.character-block__name').children.map(&:text)
10
+ end
11
+
12
+ # rubocop:disable Metrics/AbcSize
13
+ # rubocop:disable Metrics/MethodLength
14
+ def parse!
15
+ Aetheryte::Character.new(
16
+ id: id.to_s,
17
+ race: basic_info[0],
18
+ clan: clan_and_gender[:clan],
19
+ gender: clan_and_gender[:gender],
20
+ city_state: basic_info[4],
21
+ grand_company: grand_company_and_rank[:grand_company],
22
+ grand_company_rank: grand_company_and_rank[:grand_company_rank],
23
+ profile: doc.css('.character__selfintroduction').text,
24
+ jobs: Aetheryte::JobParser.new.parse(input: doc.css('.character__level li'))
25
+ )
26
+ end
27
+ # rubocop:enable Metrics/AbcSize
28
+ # rubocop:enable Metrics/MethodLength
29
+
30
+ private
31
+
32
+ attr_reader :id,
33
+ :doc,
34
+ :basic_info,
35
+ :race,
36
+ :clan,
37
+ :gender,
38
+ :guardian,
39
+ :city_state,
40
+ :grand_company,
41
+ :gc_rank
42
+
43
+ def clan_and_gender
44
+ @clan_and_gender ||= basic_info[2].split('/')
45
+
46
+ { clan: @clan_and_gender[0], gender: @clan_and_gender[1] }
47
+ end
48
+
49
+ def grand_company_and_rank
50
+ @grand_company_and_rank ||= basic_info[5].split('/')
51
+
52
+ { grand_company: @grand_company_and_rank[0], grand_company_rank: @grand_company_and_rank[1] }
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aetheryte
4
+ # Parses Job input
5
+ class JobParser
6
+ JOBS = {
7
+ 'Gladiator' => 'Gladiator',
8
+ 'Marauder' => 'Marauder',
9
+ 'Dark Knight' => 'Knight',
10
+ 'Gunbreaker' => 'Gunbreaker',
11
+ 'Conjurer' => 'Conjurer',
12
+ 'Scholar' => 'Scholar',
13
+ 'Astrologian' => 'Astrologian',
14
+ 'Sage' => 'Sage',
15
+ 'Pugilist' => 'Pugilist',
16
+ 'Lancer' => 'Lancer',
17
+ 'Rogue' => 'Rogue',
18
+ 'Samurai' => 'Samurai',
19
+ 'Reaper' => 'Reaper',
20
+ 'Archer' => 'Archer',
21
+ 'Machinist' => 'Machinist',
22
+ 'Dancer' => 'Dancer',
23
+ 'Thaumaturge' => 'Thaumaturge',
24
+ 'Summoner / Arcanist' => 'Summoner / Arcanist',
25
+ 'Red Mage' => 'Red Mage',
26
+ 'Blue Mage (Limited Job)' => 'Blue Mage',
27
+ 'Carpenter' => 'Carpenter',
28
+ 'Blacksmith' => 'Blacksmith',
29
+ 'Armorer' => 'Armorer',
30
+ 'Goldsmith' => 'Goldsmith',
31
+ 'Leatherworker' => 'Leatherworker',
32
+ 'Weaver' => 'Weaver',
33
+ 'Alchemist' => 'Alchemist',
34
+ 'Culinarian' => 'Culinarian',
35
+ 'Miner' => 'Miner',
36
+ 'Botanist' => 'Botanist',
37
+ 'Fisher' => 'Fisher'
38
+ }.freeze
39
+
40
+ attr_reader :output
41
+
42
+ def parse(input:)
43
+ input.map do |li_node|
44
+ job_name = JOBS[li_node.children.first.attributes['data-tooltip'].value]
45
+ job_level = li_node.children.last.text
46
+
47
+ { job: job_name, level: job_level }
48
+ end
49
+ end
50
+ end
51
+ end
data/lib/aetheryte.rb ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # gems
4
+ # require 'pry' # uncomment for debugging
5
+ require 'nokogiri'
6
+ require 'open-uri'
7
+
8
+ # files
9
+ require 'aetheryte/character'
10
+ require 'aetheryte/character_parser'
11
+ require 'aetheryte/job_parser'
12
+
13
+ # Hear. Feel. Think.
14
+ module Aetheryte
15
+ NO_ID_ERR_MSG = 'No :id provided'
16
+ NOT_FOUND_MSG = 'Invalid :id, Not found'
17
+ BASE_URL = 'https://na.finalfantasyxiv.com/lodestone/character'
18
+
19
+ class Error < StandardError; end
20
+
21
+ # :id must be a Integer or String of a Lodestone character URL
22
+ # example: https://na.finalfantasyxiv.com/lodestone/character/48513463/
23
+ def self.character(id: nil)
24
+ raise Error, NO_ID_ERR_MSG unless id
25
+
26
+ url = "#{BASE_URL}/#{id}"
27
+ res = URI.parse(url).open
28
+ doc = Nokogiri::HTML(res)
29
+
30
+ Aetheryte::ChracterParser.new(doc:, id:).parse!
31
+ rescue OpenURI::HTTPError
32
+ raise Error, NOT_FOUND_MSG
33
+ end
34
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aetheryte
4
+ VERSION = '0.0.0'
5
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aetheryte
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - tengille
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.10'
41
+ description:
42
+ email: melitengille@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - "./Gemfile"
48
+ - "./Gemfile.lock"
49
+ - "./LICENSE"
50
+ - "./aetheryte.gemspec"
51
+ - "./lib/aetheryte.rb"
52
+ - "./lib/aetheryte/character.rb"
53
+ - "./lib/aetheryte/character_parser.rb"
54
+ - "./lib/aetheryte/job_parser.rb"
55
+ - "./lib/version.rb"
56
+ homepage: https://github.com/tengille/aetheryte
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ rubygems_mfa_required: 'true'
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 3.1.1
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.3.7
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Aetheryte
80
+ test_files: []