change_the_subject 0.2.0 → 0.3.0
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 +4 -4
 - data/Gemfile.lock +2 -2
 - data/lib/change_the_subject/version.rb +1 -1
 - data/lib/change_the_subject.rb +19 -15
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e31b7ca05a148620fadf5080c29622314291b4ab3dc002ae76bf0385d56df57b
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8fc444360e01543dfda734714b76190847067e4897106a90c81bfb20b0cb7206
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: bc0d1ae40e9a89d7124dfdd7ffbe264a09b6a1548b8faa5af0c234f203cf7700e7812f8c437cde7d703fdc87f415faa68b358dae4c2b6e1f4523b56483945094
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: d01d1bb8684a7adb0d364e12f424edf0655c88d7a29bb6831154a713576e71d584fc4297dce151c611688eff019092848afc2e2af474798f39c288d63c4ffaa9
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/lib/change_the_subject.rb
    CHANGED
    
    | 
         @@ -6,18 +6,18 @@ require "yaml" 
     | 
|
| 
       6 
6 
     | 
    
         
             
            class ChangeTheSubject
         
     | 
| 
       7 
7 
     | 
    
         
             
              class Error < StandardError; end
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
              def self.fix(subject_terms:,  
     | 
| 
       10 
     | 
    
         
            -
                new( 
     | 
| 
      
 9 
     | 
    
         
            +
              def self.fix(subject_terms:, separators: nil)
         
     | 
| 
      
 10 
     | 
    
         
            +
                new(separators: separators).fix(subject_terms: subject_terms)
         
     | 
| 
       11 
11 
     | 
    
         
             
              end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
              def self.check_for_replacement(term:,  
     | 
| 
       14 
     | 
    
         
            -
                new( 
     | 
| 
      
 13 
     | 
    
         
            +
              def self.check_for_replacement(term:, separators: nil)
         
     | 
| 
      
 14 
     | 
    
         
            +
                new(separators: separators).check_for_replacement(term: term)
         
     | 
| 
       15 
15 
     | 
    
         
             
              end
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
              attr_reader : 
     | 
| 
      
 17 
     | 
    
         
            +
              attr_reader :separators
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
              def initialize( 
     | 
| 
       20 
     | 
    
         
            -
                @ 
     | 
| 
      
 19 
     | 
    
         
            +
              def initialize(separators: nil)
         
     | 
| 
      
 20 
     | 
    
         
            +
                @separators = separators || ["—"]
         
     | 
| 
       21 
21 
     | 
    
         
             
              end
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
              def terms_mapping
         
     | 
| 
         @@ -44,14 +44,18 @@ class ChangeTheSubject 
     | 
|
| 
       44 
44 
     | 
    
         
             
              # @param [String] term
         
     | 
| 
       45 
45 
     | 
    
         
             
              # @return [String]
         
     | 
| 
       46 
46 
     | 
    
         
             
              def check_for_replacement(term:)
         
     | 
| 
       47 
     | 
    
         
            -
                 
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
      
 47 
     | 
    
         
            +
                separators.each do |separator|
         
     | 
| 
      
 48 
     | 
    
         
            +
                  subterms = term.split(separator)
         
     | 
| 
      
 49 
     | 
    
         
            +
                  subfield_a = subterms.first
         
     | 
| 
      
 50 
     | 
    
         
            +
                  replacement = terms_mapping[subfield_a]
         
     | 
| 
      
 51 
     | 
    
         
            +
                  next unless replacement
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                  subterms.delete(subfield_a)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  subterms.prepend(replacement["replacement"])
         
     | 
| 
      
 55 
     | 
    
         
            +
                  return subterms.join(separator)
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                term
         
     | 
| 
       55 
59 
     | 
    
         
             
              end
         
     | 
| 
       56 
60 
     | 
    
         | 
| 
       57 
61 
     | 
    
         
             
              private
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: change_the_subject
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Max Kadel
         
     | 
| 
         @@ -11,7 +11,7 @@ authors: 
     | 
|
| 
       11 
11 
     | 
    
         
             
            autorequire:
         
     | 
| 
       12 
12 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       13 
13 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       14 
     | 
    
         
            -
            date: 2022-09- 
     | 
| 
      
 14 
     | 
    
         
            +
            date: 2022-09-19 00:00:00.000000000 Z
         
     | 
| 
       15 
15 
     | 
    
         
             
            dependencies:
         
     | 
| 
       16 
16 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       17 
17 
     | 
    
         
             
              name: yaml
         
     |