Sha256: d0344eb3d46523ffcd4a32152a1a6be8f5847b57b10860071ca766fac248d6be

Contents?: true

Size: 503 Bytes

Versions: 396

Compression:

Stored size: 503 Bytes

Contents

class Nucleotide
  def self.from_dna(strand)
    acids = strand.chars
    fail ArgumentError.new("Invalid DNA #{strand}") unless acids.all?(&validate)
    new(acids)
  end

  def self.validate
    proc { |acid| %w(A C G T).include?(acid) }
  end

  attr_reader :acids

  def initialize(acids)
    @acids = acids
  end

  def histogram
    {
      'A' => count('A'),
      'T' => count('T'),
      'G' => count('G'),
      'C' => count('C')
    }
  end

  def count(acid)
    acids.count(acid)
  end
end

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.179 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.178 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.177 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.176 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.175 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.174 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.173 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.172 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.171 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.170 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.169 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.167 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.166 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.165 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.164 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.163 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.162 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.161 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb
trackler-2.2.1.160 tracks/ruby/exercises/nucleotide-count/.meta/solutions/nucleotide_count.rb