Sha256: 8c12131ee6b81583ea83aef28143dcc555f5ea7a7b355869fed81e79f32e32b4

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

require 'active_support/core_ext'
require 'nicoquery/core/base'


module NicoQuery
  module Core
    class TagSearch
      include NicoQuery::Core::Base

      def initialize(tag: tag, sort: sort, order: order, page: page)
        @dynamic_segment = tag
        @params_array = params_array(sort, order, page)
      end

      private
      def host
        'www.nicovideo.jp'
      end

      def static_segment
        'tag'
      end

      def params_array(sort, order, page)
        [
          sort_param(sort),
          order_param(order),
          page_param(page),
          format
        ]
      end

      def format
        "rss=2.0"
      end

      def sort_param(sort)
        sort_string = case sort
        when :commented_at then nil
        when :view_count   then 'v'
        when :comment_num  then 'r'
        when :mylist_count then 'm'
        when :published_at then 'f'
        when :length       then 'l'
        else nil
        end

        sort_string.present? ? "sort=#{sort_string}" : ''
      end

      def order_param(order)
        order_string = case order
        when :asc  then 'order=a'
        when :desc  then 'order=d'
        else nil
        end

        order_string.presence || ''
      end

      def page_param(page)
        "page=#{page}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nicoquery-core-0.0.5.2 lib/nicoquery/core/tag_search.rb
nicoquery-core-0.0.5.1 lib/nicoquery/core/tag_search.rb