<commit_before>require 'nehm/tracks_view'

module Nehm

  ##
  # Write here description for command

  class SelectCommand < Command

    DEFAULT_LIMIT = 10

    DEFAULT_OFFSET = 0

    def initialize
      super

      add_option(:limit, 'limit NUMBER',
                'Show NUMBER tracks on each page')

      add_option(:offset, 'offset NUMBER',
                'Show from NUMBER track')
    end

    def execute
      type = @options[:args].shift
      tracks_view = TracksView.new
      track_manager = TrackManager.new(@options)
      @limit = options[:limit] ? options[:limit].to_i : DEFAULT_LIMIT
      @offset = options[:offset] ? options[:offset].to_i : DEFAULT_OFFSET

      tracks_view.next_page_proc = self.method(:next_page)
      tracks_view.prev_page_proc = self.method(:prev_page)

      loop do
        tracks =
          case type
          when /l/
            track_manager.likes(@limit, @offset)
          when /p/
            track_manager.posts(@limit, @offset)
          when nil
            UI.term 'You must provide argument'
          else
            UI.term "Invalid argument/option '#{type}'"
          end

        tracks_view.view(tracks)

      end
    end

    def arguments
     { 'likes' => 'Select likes',
       'posts' => 'Select posts' }
    end

    def program_name
      'nehm select'
    end

    def summary
    end

    def usage
    end

    private

    def next_page
      @offset += @limit
    end

    def prev_page
      @offset -= @limit if @offset >= @limit
    end

  end<commit_msg>Small improvements in 'select' command Fix indendation Remove self for next/prev_page methods<commit_after>require 'nehm/tracks_view'

module Nehm

  ##
  # Write here description for command

  class SelectCommand < Command

    DEFAULT_LIMIT = 10

    DEFAULT_OFFSET = 0

    def initialize
      super

      add_option(:limit, 'limit NUMBER',
                 'Show NUMBER tracks on each page')

      add_option(:offset, 'offset NUMBER',
                 'Show from NUMBER track')
    end

    def execute
      type = @options[:args].shift
      tracks_view = TracksView.new
      track_manager = TrackManager.new(@options)
      @limit = options[:limit] ? options[:limit].to_i : DEFAULT_LIMIT
      @offset = options[:offset] ? options[:offset].to_i : DEFAULT_OFFSET

      tracks_view.next_page_proc = method(:next_page)
      tracks_view.prev_page_proc = method(:prev_page)

      loop do
        tracks =
          case type
          when /l/
            track_manager.likes(@limit, @offset)
          when /p/
            track_manager.posts(@limit, @offset)
          when nil
            UI.term 'You must provide argument'
          else
            UI.term "Invalid argument/option '#{type}'"
          end

        # If tracks == nil, then there is a last page or there aren't tracks
        if tracks.nil?
          UI.error 'There are no more tracks'
          prev_page
          sleep(2)
          next
        end

        tracks_view.view(tracks)

      end
    end

    def arguments
      { 'likes' => 'Select likes',
        'posts' => 'Select posts' }
    end

    def program_name
      'nehm select'
    end

    def summary
    end

    def usage
    end

    private

    def next_page
      @offset += @limit
    end

    def prev_page
      @offset -= @limit if @offset >= @limit
    end

  end
{'fraction_non_alphanumeric': 0.08583308583308584, 'fraction_numerical': 0.002079002079002079, 'mean_word_length': 1.8959587274290628, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4210345', 'n_tokens_mistral': 1007, 'n_tokens_neox': 948, 'n_words': 275}