Sha256: 8045b32db51d059037e47576b0eadbdb13a1398a11252d51efcae5182ef29aef

Contents?: true

Size: 1.01 KB

Versions: 37

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EhbrsRubyUtils
  module Music
    module Ous
      class Node
        DEFAULT_LANGUAGE = 'unk'
        LANGUAGE_FILE_BASENAME = '.language'

        enable_simple_cache
        common_constructor :path do
          self.path = path.to_pathname.expand_path
        end

        def name
          real_path.basename.to_s
        end

        def language
          self_language || parent_language || DEFAULT_LANGUAGE
        end

        def language_file
          path.join(LANGUAGE_FILE_BASENAME)
        end

        def parent_language
          parent_node.if_present(&:language)
        end

        def real_path
          path.readlink_r
        end

        def self_language
          language_file.if_exist('', &:read).strip.presence
        end

        def to_s
          name
        end

        private

        def parent_node_uncached
          parent_node_class.if_present { |v| v.new(real_path.parent) }
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.44.2 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.44.1 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.44.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.41.1 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.41.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.40.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.39.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.38.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.37.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.36.1 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.36.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.35.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.33.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.32.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.31.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.30.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.29.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.28.0 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.27.1 lib/ehbrs_ruby_utils/music/ous/node.rb
ehbrs_ruby_utils-0.27.0 lib/ehbrs_ruby_utils/music/ous/node.rb