Sha256: 5420dc783b3df64c833abd3674631fc47427eb471563a6e0adceb232cead79aa

Contents?: true

Size: 840 Bytes

Versions: 6

Compression:

Stored size: 840 Bytes

Contents

module Amakanize
  class AuthorNames
    include ::Enumerable

    AUTHOR_NAME_SEPARATORS = %w(
      ,
      ,
      、
    )

    AUTHOR_NAME_SEPARATORS_REGEXP = ::Regexp.union(AUTHOR_NAME_SEPARATORS)

    # @param raw [String]
    def initialize(raw)
      @raw = raw
    end

    # @note Implementation for Enumerable
    def each(&block)
      author_names.each(&block)
    end

    private

    # @private
    # @return [Array<Amakanize::AuthorName>]
    def author_names
      segments.map do |segment|
        ::Amakanize::AuthorName.new(segment)
      end.reject do |author_name|
        author_name.to_s.empty?
      end
    end

    # @private
    # @return [String]
    def raw
      @raw
    end

    # @private
    # @return [Array<String>]
    def segments
      raw.split(AUTHOR_NAME_SEPARATORS_REGEXP)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
amakanize-0.7.0 lib/amakanize/author_names.rb
amakanize-0.6.5 lib/amakanize/author_names.rb
amakanize-0.6.4 lib/amakanize/author_names.rb
amakanize-0.6.3 lib/amakanize/author_names.rb
amakanize-0.6.2 lib/amakanize/author_names.rb
amakanize-0.6.1 lib/amakanize/author_names.rb