<commit_before>#!/usr/bin/env ruby
# @Author: vargash1
# @Name:   <NAME>
# @Email:  <EMAIL>
# @Date:   2015-02-23 10:23:20
# @Last Modified by:   vargash1
# @Last Modified time: 2015-03-26 10:46:09
require 'colorize'
class BoolCalc
    def print_all_radix(num)
        puts "Decimal:\t\tHex:".yellow
        puts "\t#{num.to_s(10)}\t\t#{num.to_s(16)}"
        puts "Binary: ".yellow
        print_nice_binary(num)
    end
    def execute()
        puts "\t--------------------X------------------".yellow
        print_all_radix(@x)
        if (@operation != 'NOT')
            puts "\t--------------------Y------------------".yellow
            print_all_radix(@y)
        end
        puts "\t-------------------#{@operation}-----------------".yellow
        case 
        when (@operation == 'AND')
            final_result = @x & @y
        when (@operation == 'OR')
            final_result = @x | @y
        when (@operation == 'XOR')
            final_result = @x ^ @y 
        when (@operation == 'NOT')
            final_result = ~@x
        when (@operation == 'SHR')
            final_result = @x >> @y
        when (@operation == 'SHL')
            final_result = @x << @y
        end
        print_all_radix(final_result)   
    end
    def check_for_errors()
        if (@operation == nil)
            abort ("ERROR, EXPECTED AN OPERATION".red)
        end
        if (@operation != "NOT")
            if (@y == nil)
                abort("ERROR, MISSING NUMBER(s)".red)
            end
        else
            if (@x == nil)
               abort("ERROR, MISSING NUMBER(s)".red)
            end 
        end
    end   
    def parse_args()
        ops = ['NOT','SHR','SHL','AND','OR','XOR']
        i = 0
        if (ARGV.length == 0 || (ARGV[0].upcase) == "-H")
            print_help()
            exit
        end
        ARGV.each do |a|
            case 
            #if ARGV[a] is letters only,check if its a valid operation
            when (a == a[/[a-zA-Z]*/])
                ops.each do |ops_elem|
                    if (a.upcase == ops_elem)
                        @operation = ops_elem
                    end
                end
            #if ARGV[a] is a number, save it.
            when (is_number(a.to_i))
                if (i == 0)
                    @x = a.to_i
                    i += 1
                else
                    @y = a.to_i
                end
            end
        end<commit_msg>Making code shorter where it can be<commit_after>#!/usr/bin/env ruby
# @Author: vargash1
# @Name:   <NAME>
# @Email:  <EMAIL>
# @Date:   2015-02-23 10:23:20
# @Last Modified by:   vargash1
# @Last Modified time: 2015-03-26 10:59:02
require 'colorize'
class BoolCalc
    def print_all_radix(num)
        puts "Decimal:\t\tHex:".yellow
        puts "\t#{num.to_s(10)}\t\t#{num.to_s(16)}"
        puts "Binary: ".yellow
        print_nice_binary(num)
    end
    def execute()
        puts "\t--------------------X------------------".yellow
        print_all_radix(@x)
        if (@operation != 'NOT')
            puts "\t--------------------Y------------------".yellow
            print_all_radix(@y)
        end
        puts "\t-------------------#{@operation}-----------------".yellow
        case 
        when (@operation == 'AND')
            final_result = @x & @y
        when (@operation == 'OR')
            final_result = @x | @y
        when (@operation == 'XOR')
            final_result = @x ^ @y 
        when (@operation == 'NOT')
            final_result = ~@x
        when (@operation == 'SHR')
            final_result = @x >> @y
        when (@operation == 'SHL')
            final_result = @x << @y
        end
        print_all_radix(final_result)   
    end
    def check_for_errors()
        if (@operation == nil)
            abort ("ERROR, EXPECTED AN OPERATION".red)
        end
        if ((@operation != "NOT" && y == nil) || @x == nil)
            abort("ERROR, MISSING NUMBER(s)".red)
        end
    end   
    def parse_args()
        ops = ['NOT','SHR','SHL','AND','OR','XOR']
        i = 0
        if (ARGV.length == 0 || (ARGV[0].upcase) == "-H")
            print_help()
            exit
        end
        ARGV.each do |a|
            case 
            #if ARGV[a] is letters only,check if its a valid operation
            when (a == a[/[a-zA-Z]*/])
                ops.each do |ops_elem|
                    if (a.upcase == ops_elem)
                        @operation = ops_elem
                    end
                end
            #if ARGV[a] is a number, save it.
            when (is_number(a.to_i))
                if (i == 0)
                    @x = a.to_i
                    i += 1
                else
                    @y = a.to_i
                end
            end
        end
{'fraction_non_alphanumeric': 0.17623637887678123, 'fraction_numerical': 0.016345347862531435, 'mean_word_length': 1.1734972677595628, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '453060', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1455, 'n_words': 361}