organo 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16bba44699065f0d0afb4bd22c4c877243dbeeb11c5d3568d146a957f00cfb69
4
- data.tar.gz: 4825637f9a142536d395f859d2309f5741f5fba336ad48eed68822c1c336f29e
3
+ metadata.gz: f7145d1efb8ac5804c2c0d786c2854dd9d92b209fceb33ca02192ae86fe0e65a
4
+ data.tar.gz: 77ff5845dd17c7ec583cbe5dace3833e52c3ca02e3d36b1b479d2140a97d908e
5
5
  SHA512:
6
- metadata.gz: 6144b9c1d789c2618a18e1dcf2ce9eac84c25d5e534fdc3d444102db216657cb4bee82186170bee45f6b5346dd6d0ac0ed6a9781b3137947cd61d1eed3f2a66d
7
- data.tar.gz: f3fc2a18ceb87932457bb11de19cdf3a88f15fa6a1b1665e5a19dbc8bc92459387e9fd293fa985efeabbb78909c40a4754a707c34519c4c889f40499aad2a023
6
+ metadata.gz: 03c4f273847259ab1af9319ec390df5badfdcf448a9208bb20992b5e1b3d8d06bd7a22580a1c54bdd7268e0595825d560ae9269bf8556b1c9178967e03aa9a26
7
+ data.tar.gz: 5003d8cbac8a154dbcb57c2698504b86faef172a705d20b9d070f786a70c0ac53013e7ac5e24dac9699fec73808bcc244e1721531a43a47d5364459f3560213e
@@ -1,6 +1,7 @@
1
1
  require_relative '../../config'
2
2
  require_relative '../../writer'
3
3
  require_relative '../../reader'
4
+ require_relative '../../tools/local_search'
4
5
 
5
6
  module Organo
6
7
  module CLI
@@ -13,15 +14,15 @@ module Organo
13
14
  argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
14
15
 
15
16
  def call(mal_id:, **)
16
- json_obj = Query.get_anime_by_id(mal_id)
17
- show = SearchShow.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'])
18
- show_type = json_obj['type']
19
- file_name = (show_type == 'TV' ? "#{json_obj['year']}_#{json_obj['season']}" : show_type.downcase)
20
- file_path = "#{Config::DEFAULT_DIR}/#{file_name}.json"
21
- show_list = File.exist?(file_path) ? Reader.read_file(file_path) : []
22
- if show_list.find_index { |s| s.id.to_s == mal_id.to_s }.nil?
17
+ if LocalSearch.find_anime_by_id(mal_id).nil?
18
+ json_obj = Query.get_anime_by_id(mal_id)
19
+ show = SearchShow.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'])
20
+ show_type = json_obj['type']
21
+ file_name = (show_type == 'TV' ? "#{json_obj['year']}_#{json_obj['season']}" : show_type.downcase)
22
+ file_path = "#{Config::DEFAULT_DIR}/#{file_name}.json"
23
+ show_list = File.exist?(file_path) ? Reader.read_file(file_path) : []
23
24
  Writer.to_file(show_list.push(show).sort_by(&:title), file_path)
24
- puts "Added anime \"#{show.title}\" (#{mal_id})"
25
+ puts "Added anime \"#{show.title}\" (#{mal_id}) in #{file_path}"
25
26
  else
26
27
  puts 'Cannot add an already existing anime'
27
28
  end
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../config'
2
4
  require_relative '../../writer'
3
5
  require_relative '../../reader'
6
+ require_relative '../../tools/local_search'
4
7
 
5
8
  module Organo
6
9
  module CLI
@@ -17,21 +20,25 @@ module Organo
17
20
  argument :type_num, type: :integer, required: false, default: 0, desc: 'The sequel type number'
18
21
 
19
22
  def call(anime_mal_id:, sequel_mal_id:, season_num:, type:, type_num:, **)
20
- json_obj = Query.get_anime_by_id(sequel_mal_id)
21
- Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
22
- shows_list = Reader.read_file(file_path)
23
- show = shows_list.find { |s| s.id.to_s == anime_mal_id.to_s }
24
- next if show.nil?
25
-
26
- if show.sequels.find { |s| s['id'].to_s == sequel_mal_id.to_s }
27
- puts 'Cannot add an already existing sequel.'
28
- else
29
- sequel = Sequel.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'], season_num, type, type_num)
30
- show.sequels.push(sequel)
31
- Writer.to_file(shows_list, file_path)
32
- puts "Added sequel \"#{sequel.title}\" (#{sequel.id}) to anime."
23
+ if LocalSearch.find_anime_by_id(sequel_mal_id).nil?
24
+ json_obj = Query.get_anime_by_id(sequel_mal_id)
25
+ sequel = Sequel.new(
26
+ json_obj['mal_id'],
27
+ json_obj['title'],
28
+ json_obj['images']['jpg']['image_url'],
29
+ season_num,
30
+ type,
31
+ type_num
32
+ )
33
+ file_path = LocalSearch.find_file_by_anime_id(anime_mal_id)
34
+ show_list = Reader.read_file(file_path).each do |show|
35
+ show.sequels.push(sequel) if show.id == anime_mal_id.to_i
33
36
  end
34
- break
37
+ show_info = show_list.find { |show| show.id == anime_mal_id.to_i }
38
+ Writer.to_file(show_list, file_path)
39
+ puts "Added sequel \"#{sequel.title}\" (#{sequel.id}) to anime \"#{show_info.title}\" (#{anime_mal_id}) in #{file_path}."
40
+ else
41
+ puts 'This sequel already exists.'
35
42
  end
36
43
  end
37
44
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../../config'
4
+ require_relative '../../tools/local_search'
4
5
 
5
6
  module Organo
6
7
  module CLI
@@ -12,13 +13,7 @@ module Organo
12
13
  argument :query, type: :string, required: true, desc: 'Search query'
13
14
 
14
15
  def call(query:, **)
15
- found_list = []
16
- Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
17
- shows_list = Reader.read_file(file_path)
18
- show = shows_list.find { |s| s.title.downcase.include? query }
19
- found_list.push(show) unless show.nil?
20
- end
21
- puts found_list.to_json
16
+ puts (LocalSearch.find_anime_by_query(query).map{ |anime| anime.to_json })
22
17
  end
23
18
  end
24
19
 
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require_relative '../reader'
5
+
6
+ module Organo
7
+ class LocalSearch
8
+
9
+ def self.find_anime_by_id(mal_id)
10
+ anime_list = Reader.read_all_files
11
+ get_anime_obj(mal_id, anime_list)
12
+ end
13
+
14
+ def self.get_anime_obj(mal_id, anime_list)
15
+ return_value = nil
16
+ anime_list.each do |anime|
17
+ if anime.id == mal_id.to_i || anime.sequels.find { |sequel| sequel['id'] == mal_id.to_i }
18
+ return_value = anime
19
+ break
20
+ end
21
+ end
22
+ return_value
23
+ end
24
+
25
+ def self.find_file_by_anime_id(mal_id)
26
+ return_value = nil
27
+ Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
28
+ anime_list = Reader.read_file(file_path)
29
+ unless get_anime_obj(mal_id, anime_list).nil?
30
+ return_value = file_path
31
+ break
32
+ end
33
+ end
34
+ return_value
35
+ end
36
+
37
+ def self.find_anime_by_query(query)
38
+ anime_list = Reader.read_all_files
39
+ return_value = []
40
+ anime_list.each do |anime|
41
+ if (anime.title.downcase.include? query.downcase) ||
42
+ (anime.sequels.find { |sequel| sequel['title'].downcase.include? query.downcase })
43
+ return_value.push(anime)
44
+ end
45
+ end
46
+ return_value
47
+ end
48
+ end
49
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Organo
4
- VERSION = '0.3.3'
4
+ VERSION = '0.3.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: organo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Louis-Philippe Fortin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-11 00:00:00.000000000 Z
11
+ date: 2023-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -117,6 +117,7 @@ files:
117
117
  - lib/organo/sequel.rb
118
118
  - lib/organo/show.rb
119
119
  - lib/organo/show_list.rb
120
+ - lib/organo/tools/local_search.rb
120
121
  - lib/organo/version.rb
121
122
  - lib/organo/writer.rb
122
123
  homepage: https://gitlab.com/dkb-weeblets/organo