<commit_before>module Hagbard

  require 'rubygems'

begin
  require 'securerandom'
rescue LoadError
  require 'activesupport'
end

  require 'hagbard/constants'

  VERSION = '0.0.1'

  class Coin
    def self.throw
begin
      SecureRandom.random_number(2)
rescue
      ActiveSupport::SecureRandom.random_number(2)
end
    end
  end

  class FourCoin
    def self.throw
      r = []
      1.upto(4) do |i|
        coin = Coin.throw
        if i == 3 and coin == 0
          coin = 1
        else
           coin = coin * i
        end
        r << coin
      end
      sum = r[0] + r[1] + r[2] + r[3]
      if r[2] == 1
        if sum < 8
          6
        else
          8
        end
      elsif r[2] == 3
        if sum < 8
          7
        else
          9
        end
      else
        raise RuntimeError, "3rd coin MUST be 3 or 1"
      end
    end
  end

  class Line
    attr_accessor :value
    def initialize(value)
      if value < 6 or value > 9
        raise ArgumentError, "invalid value, must be between 6 and 9"
      else
        @value = value
      end
    end

    def to_i
      @value
    end

    def to_s
      case @value
        when 6 then '---x---'
        when 7 then '-------'
        when 8 then '--- ---'
        when 9 then '---o---'
        else 
           raise "invalid toss result"
      end
    end
 
    def to_haml
      %Q{%img{:src => "/images/#{value}.png"}}
    end
   
    def yin?
      @value == 6 or @value == 8      
    end

    def yang?
      @value == 7 or @value == 9
    end
 
    def changing?
      @value == 6 or @value == 9
    end

    def becomes?
      case @value
        when 6 then Line.new(7)
        when 9 then Line.new(8)
        else return self
      end
    end
 
    def change!
      case @value
        when 6 then @value= 7
        when 9 then @value= 8
      end
    end
  end

  class TriGram
    attr_accessor :lines

    def initialize(args = {})
      @lines = []

      if args.empty?
        1.upto(3) do
          @lines << Line.new(FourCoin.throw)
        end
      else
        if args.has_key?(:number)
          trigram = Hagbard::TRIGRAMS.find { |t| t[:number] == args[:number] }
        elsif args.has_key?(:name)
          trigram = Hagbard::TRIGRAMS.find { |t| t[:name] == args[:name] }
        elsif args.has_key?(:bin)
          pp args[:bin]
          trigram = Hagbard::TRIGRAMS.find { |t| t[:bin] == args[:bin] }
          pp trigram
        end
 
        if trigram.nil?<commit_msg>remove some calls to pp used for debugging<commit_after>module Hagbard

  require 'rubygems'

begin
  require 'securerandom'
rescue LoadError
  require 'activesupport'
end

  require 'hagbard/constants'

  VERSION = '0.0.1'

  class Coin
    def self.throw
begin
      SecureRandom.random_number(2)
rescue
      ActiveSupport::SecureRandom.random_number(2)
end
    end
  end

  class FourCoin
    def self.throw
      r = []
      1.upto(4) do |i|
        coin = Coin.throw
        if i == 3 and coin == 0
          coin = 1
        else
           coin = coin * i
        end
        r << coin
      end
      sum = r[0] + r[1] + r[2] + r[3]
      if r[2] == 1
        if sum < 8
          6
        else
          8
        end
      elsif r[2] == 3
        if sum < 8
          7
        else
          9
        end
      else
        raise RuntimeError, "3rd coin MUST be 3 or 1"
      end
    end
  end

  class Line
    attr_accessor :value
    def initialize(value)
      if value < 6 or value > 9
        raise ArgumentError, "invalid value, must be between 6 and 9"
      else
        @value = value
      end
    end

    def to_i
      @value
    end

    def to_s
      case @value
        when 6 then '---x---'
        when 7 then '-------'
        when 8 then '--- ---'
        when 9 then '---o---'
        else 
           raise "invalid toss result"
      end
    end
 
    def to_haml
      %Q{%img{:src => "/images/#{value}.png"}}
    end
   
    def yin?
      @value == 6 or @value == 8      
    end

    def yang?
      @value == 7 or @value == 9
    end
 
    def changing?
      @value == 6 or @value == 9
    end

    def becomes?
      case @value
        when 6 then Line.new(7)
        when 9 then Line.new(8)
        else return self
      end
    end
 
    def change!
      case @value
        when 6 then @value= 7
        when 9 then @value= 8
      end
    end
  end

  class TriGram
    attr_accessor :lines

    def initialize(args = {})
      @lines = []

      if args.empty?
        1.upto(3) do
          @lines << Line.new(FourCoin.throw)
        end
      else
        if args.has_key?(:number)
          trigram = Hagbard::TRIGRAMS.find { |t| t[:number] == args[:number] }
        elsif args.has_key?(:name)
          trigram = Hagbard::TRIGRAMS.find { |t| t[:name] == args[:name] }
        elsif args.has_key?(:bin)
          trigram = Hagbard::TRIGRAMS.find { |t| t[:bin] == args[:bin] }
        end
 
        if trigram.nil?
{'fraction_non_alphanumeric': 0.10463709677419354, 'fraction_numerical': 0.02056451612903226, 'mean_word_length': 1.3828049951969261, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 7, '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': '5166131', 'n_tokens_mistral': 1778, 'n_tokens_neox': 1631, 'n_words': 508}