blob_id stringlengths 40 40 | language stringclasses 1
value | repo_name stringlengths 4 137 | path stringlengths 2 355 | src_encoding stringclasses 31
values | length_bytes int64 11 3.9M | score float64 2.52 5.47 | int_score int64 3 5 | detected_licenses listlengths 0 49 | license_type stringclasses 2
values | text stringlengths 11 3.93M | download_success bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|
31626807fa9ccc8b71c3b4013f569e411b4a618b | Ruby | mikekauffman/hash-warmup | /02_first_genre.rb | UTF-8 | 374 | 3.21875 | 3 | [] | no_license | require_relative 'people'
# What is the first genre that each person listed?
puts PEOPLE [:favorite_genres]
PEOPLE.each do |name, data|
puts data[:preferences][:favorite_genres].first
end
#OR
PEOPLE.each do |name, data|
puts data[:preferences][:favorite_genres][0]
end
#OR
PEOPLE.values.each do |data|
puts d... | true |
68087544986a521e6bc457fb94318058775b5ce7 | Ruby | paulentine/VideoStoreAPI | /test/models/customer_test.rb | UTF-8 | 2,315 | 2.515625 | 3 | [] | no_license | require "test_helper"
describe Customer do
before do
@customer = customers(:customer_1)
end
describe "Validations" do
it "must be valid with valid data" do
@customer.must_be :valid?
end
it "will not be valid without name" do
@customer.name = nil
expect(@customer.valid?).must_e... | true |
0334232ecc12ddb1120f7ae8183ca6000adfb6fe | Ruby | upstill/RecipePower-source | /lib/time_check.rb | UTF-8 | 193 | 2.734375 | 3 | [] | no_license |
def time_check_log(label)
tstart = Time.now
result = yield
tstop = Time.now
rpt = "TIMECHECK #{label}: "+(tstop-tstart).to_s+" sec."
logger.debug rpt
result
end
| true |
d5264aa99cecc5b619dbd8f64b2b6682135d763c | Ruby | NYDrewReynolds/my_enigma | /test/offset_test.rb | UTF-8 | 841 | 2.65625 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest'
require 'minitest/pride'
require './lib/offset.rb'
class OffsetTest < Minitest::Test
def setup
key = Key.new("41521")
date = Date.new("020315")
@offset = Offset.new(key, date)
end
def test_it_exists
assert Offset
end
def test_it_combines_a_valu... | true |
a3ef0a09f63b220cc0bd5a1a36fccb0ef6684071 | Ruby | hack3rvaillant/convert_svg_string_to_gcode_gem | /lib/convert_svg_string_to_gcode/helpers/create_gcode_array_from_svg_commands.rb | UTF-8 | 1,881 | 3.1875 | 3 | [] | no_license | require 'convert_svg_string_to_gcode/constants/plotter_config'
class CreateGCodeArrayFromSVGCommands
def self.perform(commands, options = {step: 0.20})
start_point = nil
step=options[:step]
gcode_array = commands.map do |c|
case c.type
when ConversionConstants::MOVE
move_to_point(c)
... | true |
b46e0db34ad6e5f5d792a680ccf195d0f765f9e7 | Ruby | scoiatael/parrhasius | /lib/parrhasius/downloaders/fourchan.rb | UTF-8 | 927 | 2.703125 | 3 | [] | no_license | # frozen_string_literal: true
require 'down'
require 'nokogiri'
require 'securerandom'
module Parrhasius
module Downloaders
class FourChan # rubocop:todo Style/Documentation
include Enumerable
def download(link)
img_link = link.attributes['href']
return unless img_link
[Sec... | true |
ed7330d4e49edd5a9da7f625d3365939e9786ba7 | Ruby | rafiamafia/dotfiles | /bin/inspect | UTF-8 | 1,402 | 3.140625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
class Inspector
attr_accessor :argv, :stdin, :stdout
def initialize(argv, stdin, stdout)
self.argv = argv
self.stdin = stdin
self.stdout = stdout
end
def call
if argv.any? then inspect_files argv
else inspect_stream stdin
end
end
private
def... | true |
8887991ea79b529a7ea788444f350610928cb049 | Ruby | zlhhhhhhh/hw-ruby-intro | /lib/ruby_intro.rb | UTF-8 | 1,599 | 3.96875 | 4 | [] | no_license | # When done, submit this entire file to the autograder.
# Part 1
def sum arr
# YOUR CODE HERE
sum = 0;
for i in arr
sum += i
end
return sum
end
def max_2_sum arr
# YOUR CODE HERE
max_sum = 0;
max1 = -Float::INFINITY;
max2 = -Float::INFINITY;
for i in arr
if i >= max1
max2 = max1
... | true |
0934365315793173926e851a9491842f6a95b9c2 | Ruby | henix/shielddns | /regexptrie.rb | UTF-8 | 1,480 | 3.421875 | 3 | [] | no_license | require 'stringio'
class RegexpTrie
# @param strs: Array[String]
# @param out: IO
def self.build(strs, out = nil)
if out
build_depth(strs, 0, out)
else
out = StringIO.new
build_depth(strs, 0, out)
out.string
end
end
private
def self.build_depth(strs, depth, out)
s... | true |
1acf155a6b6fb93fb9deb35571a75855b671e7db | Ruby | FayeKeegan/checkers | /empty_square.rb | UTF-8 | 123 | 2.6875 | 3 | [] | no_license | class EmptySquare
def initialize
end
def to_s
" "
end
def empty?
true
end
def checker?
false
end
end
| true |
a6e6bf9d0819d5c924ca63e5be54cfee7c15ad5f | Ruby | Stanis1av/Ruby | /Ruby/Двоичные числа/1.0.0 app.rb | UTF-8 | 1,082 | 3.546875 | 4 | [
"MIT"
] | permissive | # def convert_to_binary(n)
# ch = n / 2
# ost = n % 2
# result = []
# result << ost
# loop do |v|
# ost = ch % 2
# ch = ch / 2
# result << ost
# break if ch == 0
# end
# answer = result.reverse.join.to_i
# puts answer
# end
# convert_to_binary(6)
def convert_to_b... | true |
a9a4f9059cab40023b4020eab3e906f4cc8987b8 | Ruby | fairpay-coop/fairpay-server | /app/models/binbase.rb | UTF-8 | 1,682 | 2.671875 | 3 | [] | no_license | class Binbase < ActiveRecord::Base
# create_table :binbases do |t|
# t.string :bin, index: true
# t.string :card_brand
# t.string :card_type
# t.string :card_category
# t.string :country_iso
# t.string :org_website
# t.string :org_phone
# t.references :binbase_org
# t.timestamps n... | true |
22b7651d770574fb0f2f406753afcdd070ee90a7 | Ruby | ericburleson/LearntoProgram | /LearnToProgram11.rb | UTF-8 | 3,578 | 3.109375 | 3 | [] | no_license | #LearnToProgram11.rb
#The filename doesn't have to end with ".txt" but since it is valid, why not?
filename = 'ListerQuote.txt'
test_string = 'I promise that I swear absolutely that' +
'I will never mention gazpacho soup again.'
#The 'w' here is for write-access to the file
#since we are trying to wr... | true |
1211a9afa27718d479ed5f02a5da78ab5569f5c0 | Ruby | thilo/coworking-framework | /db/seeds.rb | UTF-8 | 5,231 | 2.65625 | 3 | [] | no_license | # encoding: utf-8
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.cre... | true |
58b87a0dbd38379baa73fdef53bce44b9c73c032 | Ruby | nicky-isaacs/mapquestsearch | /lib/mapquestsearch.rb | UTF-8 | 1,713 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'mapquestsearch/version'
require 'rest_client'
require 'json'
require 'rexml/document'
class MapQuestSearch
CITY = 'city'
LAT_LONG = 'lat_long'
ALLOWED_FORMATS = [:json, :xml, :html]
RETRY_COUNT = 5
@@_default_format = nil
#----------------------------
def self.default_format
@@_default_fo... | true |
8a359e83e2c7bba641735b9a54a8060438f16f51 | Ruby | TatsuyaIsamu/Arrays | /test5.rb | UTF-8 | 768 | 3.84375 | 4 | [] | no_license | 4.8.5 ブロックローカル変数
numbers = [1, 2, 3, 4]
sum = 0
numbers.each do |n; sum|
sum = 10
sum += n
p sum
end
sum # ブロック外なので sum = 0 になる
4.8.6 繰り返し処理以外でも使用されるブロック
sample.rb 参照
4.8.7 do..end と {} の結合度の違い
a = [1, 2, 3]
a.delete(10) do
"NG"
end
a.delete 10 do
"NG"
end
... | true |
873e050ff93467ea925308d0b0755f5f4bcd7d25 | Ruby | cjmurphy93/aA-classwork | /w01/w1d1/references_exercise/destination_city.rb | UTF-8 | 770 | 3.453125 | 3 | [] | no_license | def dest_city(paths)
# new_path = paths.flatten
# new_path.each_with_index do |city, i|
# (0...paths.length - 1).each do |j|
# if paths[j][0] == city
# new_path[i] = ""
# end
# end
# end
# new_path.each do |city|
# if city != ""
# ... | true |
e03f97901874221520730fda2c40bff2e21b1425 | Ruby | jinnujohnson/Exercism_Problems | /ruby/series/series.rb | UTF-8 | 409 | 3.765625 | 4 | [] | no_license | class Series
def initialize(string)
@string = int_conversion(string)
end
def int_conversion(s)
s.chars.to_a.map(&:to_i)
end
def slices(count)
slice = []
if count > @string.length
fail ArgumentError.new('Unable To Slice')
end
i = -1
begin
i += 1
j = i + count - ... | true |
bd1f3da98e73ae0d3e50971d0bfc7d05c2d8bb0b | Ruby | libdx/twee | /model.rb | UTF-8 | 1,480 | 2.84375 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'singleton'
require 'yaml'
module Twee
UserConfigDirName = ".twee"
UserConfigMainFileName = "config.yml"
class Config
include Singleton
attr_accessor :write_password
alias_method :write_password?, :write_password
def self.load
Config.instance
end
def initialize
sup... | true |
8c24a0b45894dd99f14be21691ab01afd45e0a2a | Ruby | startling/sullivan | /spec/sullivan_spec.rb | UTF-8 | 1,120 | 2.890625 | 3 | [
"MIT"
] | permissive | require 'sullivan'
describe Sullivan do
describe ".validation" do
it "provides a convenient way to access the built-in validations" do
v = Sullivan.validation do
hash(
string_matching: string_matching(/\Al(ol)+\z/, error: "must be be a laugh"),
kind_of: kind_of(Numeric)
... | true |
87193aae1af9156f5b317a7fd26193403005adac | Ruby | mikoyan/name_checker | /lib/name_checker/twitter_checker.rb | UTF-8 | 2,153 | 2.8125 | 3 | [
"MIT"
] | permissive | # NOTE: This is rate limited to 150 requests per hour.
# TODO: Add OAuth or some other authentication in order
# to get my request limit rate increased.
module NameChecker
class TwitterChecker
include HTTParty
include Logging
MAX_NAME_LENGTH = 16
base_uri "http://api.twitter.com"
@service_name = ... | true |
b2bcdc730a352b36ab495d46c669955a1bdf3b17 | Ruby | mwagner19446/wdi_work | /w02/d02/Marco/morning_exercises.rb | UTF-8 | 1,297 | 3.828125 | 4 | [] | no_license | class Person
def initialize(name)
@name = name
end
def self.learn
puts "I'm a class method"
puts self
end
def learn
puts "I'm an instance method"
puts self
end
def hello
self.learn
end
def hello_again
learn
end
end
pj = Person.new("PJ") #=>=> #<Person:0x007ff03a0ece00 @name="PJ">
pj.learn #=>I'm a... | true |
0f6d9d006226b3c77e3b9bd348c55cd465fe79b4 | Ruby | andrewdavidburt/epicodus_squish_underflow | /app/models/question.rb | UTF-8 | 997 | 2.65625 | 3 | [] | no_license | class Question < ActiveRecord::Base
has_many :answers
belongs_to :user
validates :title, :presence => true
validates :description, :presence => true
# def average_rating
# if (self.reviews.size > 0)
# sum = 0
# self.reviews.each do |review|
# sum += review.rating
# end
# ... | true |
7ac49658abdf10a0771e790409ba125ea9165a67 | Ruby | BRIMIL01/readruby | /spec/readruby/invocation_spec.rb | UTF-8 | 7,690 | 2.953125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | describe ReadRuby::Invocation, ".new" do
it "requires a Class as the first argument" do
lambda do
ReadRuby::Invocation.new(String, :[], 'text')
end.should_not raise_error
lambda do
ReadRuby::Invocation.new('string', :[], 'text')
end.should raise_error(ArgumentError)
end
it "require... | true |
51180555cb12ff89c059627c022ee07be4243ff1 | Ruby | edvelezg/unb-dw | /mysql_work/connect.rb | UTF-8 | 2,720 | 2.890625 | 3 | [] | no_license | #!/usr/bin/ruby -w
# simple.rb - simple MySQL script using Ruby MySQL module
# update user set Password=PASSWORD('mondrian') WHERE User='ed';
# SELECT book_id, place_id, count(*) from sentence_and_place group by book_id, place_id;
# SELECT book_id, t1.place_id, t2.place_name, COUNT(*) FROM sentence_and_place AS t1 IN... | true |
dda3c7f03868d963463f5f9d639f3fc81b2cf5a2 | Ruby | saihdavis/array-CRUD-lab-onl01-seng-pt-032320 | /lib/array_crud.rb | UTF-8 | 926 | 3.5625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def create_an_empty_array
[]
end
def create_an_array
my_array = ["one", "two", "three", "four"]
end
def add_element_to_end_of_array(array, element)
my_array = ["one", "two", "three", "four"]
my_array.push("arrays!")
end
def add_element_to_start_of_array(array, element)
my_array = ["one", "two", "three",... | true |
02abe07aab100c9d13c3e3bbf92ffe8540f3c93f | Ruby | PabloK/CLL | /lib/models/ability.rb | UTF-8 | 3,087 | 2.796875 | 3 | [] | no_license | #encoding: utf-8
class Ability
include DataMapper::Resource
property :id, Serial, :key => true
property :name, String, :unique => true, :required => true, :messages => {
:presence =>"Förmågan kan inte enbart inehålla mellanslag."
}
# A measurement of how much this ability is embraced
property :nu... | true |
61c58497769c55580a9680dd5c02a8fa2c81ef25 | Ruby | mdheller/rletters | /app/lib/r_letters/analysis/count_articles_by_field.rb | UTF-8 | 7,838 | 2.71875 | 3 | [
"BSD-3-Clause",
"MIT",
"Apache-2.0"
] | permissive | # frozen_string_literal: true
module RLetters
module Analysis
# Code for counting the number of articles in a dataset, grouped by a field
#
# @!attribute field
# @return [Symbol] the field to group by
# @!attribute dataset
# @return [Dataset] if set, the dataset to analyze (else the entir... | true |
3778b0cdd763ffb1283a7234190973f0d66729d7 | Ruby | diegocasmo/guitarlyco | /app/models/article.rb | UTF-8 | 488 | 2.515625 | 3 | [] | no_license | class Article < ActiveRecord::Base
# Validations
validates_presence_of :title, :slug, :video_link, :body
validates_uniqueness_of :title
# Callbacks
before_validation :add_article_slug
def add_article_slug
return unless self.title.present?
self.slug = self.title.parameterize
end
# Paginates a ... | true |
1c9c0da28e045d9b44a105241b8afac4dcb7da43 | Ruby | craigsheen/coloruby | /lib/coloruby.rb | UTF-8 | 1,340 | 3.609375 | 4 | [] | no_license | class Coloruby
def self.lighten(hex_color, amount=0.3)
hex_color = hex_color.gsub('#','')
rgb = hex_color.scan(/../).map { |color| color.hex }
rgb[0] = [(rgb[0].to_i + 255 * amount).round, 255].min
rgb[1] = [(rgb[1].to_i + 255 * amount).round, 255].min
rgb[2] = [(rgb[2].to_i + 255 * amount).rou... | true |
e80b81c7889aaf3d3c023ebf5ca42a9555932f94 | Ruby | walter-petkanych/lessons | /happy1.rb | UTF-8 | 226 | 3.828125 | 4 | [] | no_license | puts('enter your name')
name = gets()
puts('happy birthday ' + name)
puts('what year is now?')
year = gets()
puts('what is the year you are boarned')
boarned = gets()
age = year.to_i - boarned.to_i
puts('you are ' + age.to_s) | true |
6d1cc7c9c8ea93d31dab036d0df42cbf66ae0a93 | Ruby | Jacura/Ruby-Practice-Project | /Task5/exception_handling.rb | UTF-8 | 171 | 3.125 | 3 | [] | no_license | x = gets.chomp.to_i
y = gets.chomp.to_i
def add(a,b)
begin
c = a + b
rescue Exception => e
puts e.message
ensure
puts c
end
end
add(x,y)
| true |
769dedb4b654d0d5ec86cb75fb891f9eb561a896 | Ruby | ceritium/gosu-in-space | /libs/shot.rb | UTF-8 | 611 | 3.15625 | 3 | [] | no_license | class Shot
attr_reader :y, :x, :time
def initialize(window, x, y, angle)
@image = Gosu::Image.new(window, "media/empire_laser.png", false)
@vel_x = @vel_y = @angle = 0.0
@x, @y, @angle = x, y, angle
@vel_x += Gosu::offset_x(@angle, 17)
@vel_y += Gosu::offset_y(@angle, 17)
@time = Time.now
... | true |
3aa4ffbe8f94409af6a3cac2faa527d224ed88c2 | Ruby | toryu1121/puyoaptana | /puyoclass/yokoku.rb | UTF-8 | 1,467 | 3.359375 | 3 | [] | no_license | #! ruby -Ku
require './matrixx'
# require './action' #後でコメントアウト, 消さなきゃaction.rbを実行できない
class Yokoku
def initialize(yokoku, input_key, puyo, width, roll)
@yokoku = yokoku
@input_key = input_key
@puyo = puyo
@width = width
@roll = roll
#p @yokoku
#p @input_key = 6
case @input_key... | true |
ab7642f08b474cbfd9a1b2fca6eb5cd39551d3c0 | Ruby | jweissman/dragon | /lib/dragon/events/person_encountered_event.rb | UTF-8 | 347 | 2.59375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Dragon
module Events
class PersonEncounteredEvent < Event
attr_reader :person
def initialize(person: nil)
@person = person
end
def describe
"You encounter a person: #{person.describe}"
end
def actions
[ converse_with(person), ignore(person) ]
... | true |
4561a3fcc3af24225e20136bb64bcce55aaea665 | Ruby | mois3x/ruby-tsv | /spec/lib/tsv_spec.rb | UTF-8 | 3,397 | 2.6875 | 3 | [
"MIT"
] | permissive | require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
describe TSV do
let(:filename) { 'example.tsv' }
describe "#parse" do
let(:header) { nil }
let(:parameters) { { header: header } }
context "given a string with content" do
let(:content) { IO.read(File.join(File.dirname(__FILE__),... | true |
2d473d9734e6d6191b50361e825c069cae5b3d29 | Ruby | CodingMBA/ls_101_lesson_3 | /easy_2_7.rb | UTF-8 | 255 | 2.8125 | 3 | [] | no_license | flintstones = %w(Fred Barney Wilma Betty BamBam Pebbles)
flintstones.push("Dino", "Hoppy")
flintstones.push("Dino").push("Hoppy")
flintstones.unshift("Dino", "Hoppy")
flintstones.unshift("Dino").unshift("Hoppy")
flintstones.concat(%w(Dino Hoppy))
p flintstones | true |
f5a4b8fb68f4946d83415a807fa7358a92088d92 | Ruby | everypolitician-scrapers/uzbekistan-majlis | /scraper.rb | UTF-8 | 2,446 | 2.75 | 3 | [] | no_license | #!/bin/env ruby
# encoding: utf-8
require 'scraperwiki'
require 'nokogiri'
require 'pry'
require 'set'
require 'open-uri/cached'
OpenURI::Cache.cache_path = '.cache'
class String
def tidy
self.gsub(/[[:space:]]+/, ' ').strip
end
end
def noko_for(url)
Nokogiri::HTML(open(url).read)
end
def scrape_letters(... | true |
0e8f570eeef6bc6826f689ef4023d0b087c76ea5 | Ruby | nikomc0/debt_calculator_sinatra | /app/helpers/finance_calculations.rb | UTF-8 | 2,208 | 2.96875 | 3 | [] | no_license | module FinanceCalculations
# Credit Card Minimum Payment is just a simple percentage of the principal.
# def minimum_payment
# BigDecimal(self.principal) * 0.03
# end
def minimum_payment(*args)
apr = self.apr
principal = self.principal
args.map do |x|
if x.include?('principal')
principal = BigDecim... | true |
7170dd02c2b1cb7f02e7bb580b1fa060eaf54487 | Ruby | binamkayastha/WunCur | /src/extlib/wlist/lib/wlist.rb | UTF-8 | 3,334 | 2.875 | 3 | [
"MIT"
] | permissive | require 'json'
require 'optparse'
OPTIONS = {}
OPTIONS_PARSER = OptionParser.new do |opts|
opts.banner = "Usage: example.rb [options]"
opts.on("-v", "--verbose", "Show verbose statements") do |v|
OPTIONS[:verbose] = v
end
opts.on("-i ID", "--id ID", Integer, "Object identifier") do |v|
OPTIONS[:id] = v... | true |
10c7b9459ee4dbfdc81e62f4dabbdec2c4626d63 | Ruby | AgileVentures/WebsiteOne | /app/services/markdown_converter.rb | UTF-8 | 304 | 2.578125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
class MarkdownConverter
attr_reader :markdown
private :markdown
def initialize(markdown)
@markdown = markdown
end
def as_html
converted_markdown.html_safe
end
private
def converted_markdown
Kramdown::Document.new(markdown).to_html
end
end
| true |
1c008717a900357bbf0a965c97df8d0667641959 | Ruby | codenameuriel/getting-remote-data-apis-and-iteration-nyc-web-021720 | /lib/command_line_interface.rb | UTF-8 | 372 | 3.875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def welcome
puts "\nWelcome to the Star Wars program...\nYou can search what movies a character appeared."
end
def get_character_from_user
puts "please enter a character name"
# use gets to capture the user's input. This method should return that input, downcased.
character_name = gets.chomp
# .downcase.str... | true |
915400e5f0b141c007d455e658aa0db77a8cbce8 | Ruby | Aditya-Chowdhry/examopedia-rails | /app/models/exam.rb | UTF-8 | 3,584 | 2.5625 | 3 | [] | no_license | # create_table :exams do |t|
# t.string :title
# t.string :description
# t.integer :section
# t.integer :level
# t.attachment :image
# t.datetime :exam_date
# t.date :form_release_date
# t.date :form_last_date
# t.string :link1_name
# t.string :link1
# t.string :li... | true |
9ea604b33e215031ab3d1287422569ba8e8ae512 | Ruby | nathanl/.dotfiles | /bin/prune_merged | UTF-8 | 893 | 2.8125 | 3 | [] | no_license | #!/usr/bin/env ruby
# Ruby script to interactively prune branches that have been merged
PERMANENT_BRANCHES = %w[develop main master staging release]
current_branch = %x{git rev-parse --abbrev-ref HEAD}.strip
unless PERMANENT_BRANCHES.include?(current_branch)
puts "To run this, please check out one of #{PERMANENT_B... | true |
3347a9a2f9b0606e5000ac4bbf4eb55c92fd7bea | Ruby | delmereccles/periodic | /lib/periodic/parser.rb | UTF-8 | 2,456 | 3.265625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Periodic
module Parser
def parse(string, options = { :bias => :seconds})
return Parseable.new(string, options[:bias]).seconds
end
private
class Parseable
def initialize(string, bias)
@string = string
validates_inclusion_of_numeral_in_string
@bias = bias
... | true |
857a5671778247cc6d301fd27fa1b1f7e91dca1b | Ruby | Exzaiden/loomio-sms-gateway-1 | /loomioAPI.rb | UTF-8 | 3,604 | 3.0625 | 3 | [] | no_license | require_relative 'masterConfig'
require 'net/http'
require 'rubygems'
require 'json'
##
# Accesses the API on Loomio's end
#
class LoomioAPI
@uri = URI.parse(MasterConfig.getAPIServer)
@http = Net::HTTP.new @uri.host, @uri.port
@path = MasterConfig.getAPIPath
@handlerURL = MasterConfig.getAPIHandler
$stderr.... | true |
8bc819ff6b9791a627d55821fa9c068cb36a9949 | Ruby | Ricardo875/rails-yelp-mvp | /db/seeds.rb | UTF-8 | 1,161 | 2.546875 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Ch... | true |
26ac6af507c5b978e29e5df0a8762de76e6a6b6a | Ruby | jodiealaine/colorizr | /example.rb | UTF-8 | 525 | 3.421875 | 3 | [
"MIT"
] | permissive | require 'colorizr'
# Should colorize the specified text with the color specified
puts "John".red
puts "Paul".green
puts "George".blue
puts "Ringo".yellow
puts "John".pink
puts "Paul".light_blue
puts "George".white
puts "Ringo".light_grey
puts "John".black
# Should only colorize the text with a colorize method called
... | true |
fcbda4b36182491bfb6b0d828b176289d51d975a | Ruby | Alexander-Zyurkalov/MakePhrases | /lib/snenglish/word_rates.rb | UTF-8 | 737 | 2.515625 | 3 | [] | no_license |
module SNEnglish
class WordRate < SNEnglish::Base
@HEADER = [
"number_of","word","part_of_speech","number_of_files","id"
]
def add_columns_to_csv(row)
if row.count < 5
row.push self.id
else
... | true |
3171bf5155fde1b4d8fa5c4d03fd3763a40a1cee | Ruby | aetheric-typewriter/w2d3 | /tdd_test/lib/tdd.rb | UTF-8 | 2,351 | 3.890625 | 4 | [] | no_license | require "byebug"
def my_uniq(arr)
hash = {}
arr.each do |ele|
hash[ele] = true
end
hash.keys
end
def two_sum(arr)
results = []
(0...(arr.length)).each do |i|
((i + 1)...(arr.length)).each do |j|
results << [i, j] if arr[i] + arr[j] == 0
end
end
resu... | true |
6d90f1ba851f2743253b86c056bacaea9412d740 | Ruby | jannesbrunner/ruby-workshop | /1_navigator/solve.rb | UTF-8 | 159 | 2.671875 | 3 | [] | no_license | require './navigator'
directions = File.read('./input.txt')
navigator = Navigator.new
navigator.follow(directions)
puts "The answer is #{navigator.position}"
| true |
06d50424c17c4052ce908444bbe6c157ea05502e | Ruby | razic/armduino | /arm.rb | UTF-8 | 1,576 | 2.625 | 3 | [] | no_license | # require libraries
%w[ rubygems osc-ruby serialport ].each { |lib| require lib }
# connect to arduino
@arduino = SerialPort.new "/dev/tty.usbserial-A800etAZ", 115200
# initial arm position
@shoulder, @forearm, @elbow, @claw = 180, 50, 60, 35
# setup osc server so we can listen for messages from the multi-touch on m... | true |
e7b219345d533602cafc9be2d65562f096393bb4 | Ruby | meyouhealth/flexible_enum | /spec/identity_values_spec.rb | UTF-8 | 2,103 | 2.734375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe "identity values" do
it "retrieves the details for the current value" do
register = CashRegister.new
register.status = CashRegister::NOT_ACTIVE
expect(register.status_details).to eq(my_custom_option: "Nothing to see here", value: 10)
end
it "retrieves the name for the... | true |
9d29b10da02e99a317848df56c8201096628fe71 | Ruby | pks/nlp_scripts | /first-upper | UTF-8 | 119 | 2.765625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'zipf'
while line = STDIN.gets
line.strip!
line[0] = line[0].upcase
puts line
end
| true |
6d67117f36ab74a8896664b35d0423b771c940e0 | Ruby | yuto0139/bonus-drink | /bonus_drink.rb | UTF-8 | 277 | 3.203125 | 3 | [] | no_license | class BonusDrink
def self.total_count_for(amount)
# 3本未満の場合はamountの値が答え
return amount if amount < 3
# 3本以上の場合はamountにおまけの本数を加えた値が答え
return amount + (amount - 1) / 2 if amount >= 3
end
end
| true |
50f441a647ce831827bf257e252cb02640206a1e | Ruby | ankit8898/tic-tac-toe | /lib/tic_tac_toe/diagonal.rb | UTF-8 | 217 | 2.765625 | 3 | [] | no_license | #Diagonal
#
# A diagonal in a grid
module TicTacToe
class Diagonal
attr_reader :position,:cells
def initialize(opts = {})
@position = opts[:position]
@cells = opts[:cells]
end
end
end
| true |
6f1d9e4da61fbf21b53ddb492e9593c2e883a9b0 | Ruby | rkononov/iron_worker_ruby | /test/test_inheritance.rb | UTF-8 | 386 | 2.59375 | 3 | [
"BSD-2-Clause"
] | permissive | require_relative 'test_base'
class TestInheritance < TestBase
def test_who_am_i
worker = TestWorker2.new
puts "1: " + worker.who_am_i?
puts "2: " + worker.who_am_i2?
end
def test_multi_subs
t3 = TestWorker3.new
t3.queue
t3.wait_until_complete
puts "LOG:"
log = t3.get_log
... | true |
cb9022e4c9364f382bc37aab7cd9d51d6936e745 | Ruby | aizunoinu/RubyLife | /正規表現/test9-1.rb | UTF-8 | 606 | 3.703125 | 4 | [] | no_license | #文字列の先頭に対してマッチ処理を行う
#行の先頭に対してマッチ処理を実施する。
def check1(str)
print "#{str}は ^abc に"
if /^abc/ =~ str then
print "マッチします\n"
else
print "マッチしません\n"
end
end
#文字列の先頭に対してマッチ処理を実施する。
def check2(str)
print "#{str}は \\Aabc に"
if /\Aabc/ =~ str then
print "マッチします\n"
else
... | true |
0282e3f86ec023d6b3ec76bef6b0acc600f8add8 | Ruby | franky-og/ruby-objects-belong-to-lab-dumbo-web-82619 | /lib/author.rb | UTF-8 | 127 | 2.703125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Author
# def initialize(name)
# @name = name
# end
def name=(new_name)
@name = new_name
end
attr_reader :name
end | true |
cbc9bacc6c0e7e98de649fd4d90ee7c1014c1a25 | Ruby | iEv0lv3/enigma | /lib/modules/shift.rb | UTF-8 | 1,533 | 3.453125 | 3 | [] | no_license | require_relative 'character'
module Shift
include Character
def create_shift(new_key, new_date)
shift_key = new_key.make_keys(new_key.digits)
shift_offset = new_date.create_offset(new_date.date)
key_plus_offset(shift_key, shift_offset)
end
def key_plus_offset(shift_key, shift_offset)
shift_of... | true |
89618ed5cf25d1b46170e36b519e3e26a6b6d99b | Ruby | sethpuckett/gm-treasure | /app/models/treasure_haul.rb | UTF-8 | 479 | 3.125 | 3 | [] | no_license | # frozen_string_literal: true
class TreasureHaul
attr_accessor :cp, :sp, :ep, :gp, :pp
def initialize(cp: 0, sp: 0, ep: 0, gp: 0, pp: 0)
@cp = cp
@sp = sp
@ep = ep
@gp = gp
@pp = pp
end
def add(type, value)
case type
when :cp then @cp += value
when :sp then @sp += value
whe... | true |
b69ded35f7a174d068fafe802b55a46a4b52e8c2 | Ruby | jessiehuff/ttt-with-ai-project-v-000 | /lib/game.rb | UTF-8 | 1,887 | 4.0625 | 4 | [] | no_license | require 'pry'
class Game
attr_accessor :board, :player_1, :player_2
WIN_COMBINATIONS = [
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[6,4,2]
]
def initialize(player_1= Players::Human.new("X"), player_2= Players::Human.new("O"), board = Board.new)
@board ... | true |
ee11decd0996a7b0c0f48153d2bccc7564cf0992 | Ruby | mmichael0413/RomanNumerals | /roman_numerals_spec.rb | UTF-8 | 1,577 | 3.5 | 4 | [] | no_license | require 'rspec'
require_relative 'roman_numerals'
describe RomanNumerals do
let(:roman_numerals) { RomanNumerals.new }
describe '#run!' do
context 'when the user enters a valid number' do
it 'should call the answer! method with the result' do
allow_any_instance_of(RomanNumerals).to receive(:wel... | true |
b21bb49aa20eedbc5aaca7fc95be748f8d58e8a5 | Ruby | omajul85/well-grounded-rubyist | /self_scope_and_visibility/method_access_rules/protected.rb | UTF-8 | 438 | 4.5 | 4 | [] | no_license | class C
def initialize(n)
@n = n
end
def compare(c)
if c.n > n
puts "The other object's n is bigger"
else
puts "The other object's n is the same or smaller"
end
end
protected
attr_reader :n
end
c1 = C.new(100)
c2 = C.new(101)
c1.compare(c2)
# The object doing the comparing (... | true |
c1e6cb9c9d8a668367de11085f8f23186bfb7736 | Ruby | Syft-Application/companies-house-api | /lib/companies_house/request.rb | UTF-8 | 1,631 | 2.515625 | 3 | [] | no_license | # frozen_string_literal: true
require 'net/http'
require 'virtus'
module CompaniesHouse
# This class manages individual requests.
# Users of the CompaniesHouse gem should not instantiate this class
class Request
include Virtus.model
attribute :api_endpoint
attribute :api_key
attribute :query
... | true |
28aab4056689a65fb3c8227c4b3b7cf0099bce5e | Ruby | walterchabla/phase-0-tracks | /ruby/gps6/my_solution.rb | UTF-8 | 3,841 | 4.40625 | 4 | [] | no_license | # Virus Predictor
# I worked on this challenge [by myself].
# We spent [2] hours on this challenge.
# EXPLANATION OF require_relative
#require_relative is having the code from another file being avaliable in this file, using a relative path.
#require would work for files that are outside the directory or folder, is l... | true |
53c23dff0cb815e1908f3a477161514b412d8be0 | Ruby | nkinney/rrobots | /PolarIce/Driver.rb | UTF-8 | 3,776 | 3.15625 | 3 | [] | no_license | #The Driver is responsible for turning and moving the tank.
class Driver
include Rotator
MAXIMUM_ROTATION = 10
INITIAL_ROTATION = 0
INITIAL_DESIRED_HEADING = nil
INITIAL_DESIRED_POSITION = nil
MAXIMUM_SPEED = 8
MAXIMUM_ACCELERATION = 1
INITIAL_ACCELERATION_RATE = 0
INITIAL_DESIRED_SP... | true |
b5448977c7b7a4cee4914e8fce2367d1dad4e630 | Ruby | elzj/ao3_api | /app/archive_search/search/range_parser.rb | UTF-8 | 3,193 | 3.28125 | 3 | [] | no_license | # frozen_string_literal: true
module Search
# Handles user-inputted rangelike data and outputs
# actual number and date ranges if possible
class RangeParser
TIME_REGEX = %r{
^(?<operand>[<>]*)\s*
(?<amount>[\d -]+)\s*
(?<period>year|week|month|day|hour)s?
(?<ago>\s*ago)?\s*$
}xi
... | true |
fdcc7480853a603d69e61c62ab1d719ea10a82da | Ruby | danstutzman/generate-bilingual-sentence-pairs | /OLD/load_spanish.rb | UTF-8 | 14,859 | 2.59375 | 3 | [] | no_license | require 'pp'
require './models_fast'
VOCAB_HEIGHT = 1
SUFFIX_HEIGHT = 1
STEM_HEIGHT = 1
CONJUGATION_HEIGHT = 2
TEMPLATE_HEIGHT = 3
PHRASE_HEIGHT = 4
SENTENCE_HEIGHT = 5
def to_sentence s
s[0].upcase + s[1..-1] + '.'
end
connect_to_db! true
new_prompt 'vocab_l1', 'vocab_l2', 'Translate... | true |
adfa701b63ae2a1e702d86adbcb06ecabf2dec51 | Ruby | markandrus/Templatron | /util/makeMasthead.rb | UTF-8 | 619 | 2.546875 | 3 | [] | no_license | #! /usr/local/bin/ruby
require 'rubygems'
begin
require 'RMagick'
include Magick
def makeMasthead(title, outputPng)
title.strip!
text = Draw.new
text.font = 'Gotham-Rounded-Light'
text.pointsize = 28
text.gravity = SouthWestGravity
hdr = Image.new(650, 53) { self.background_color = 'none' }
text.anno... | true |
bc66e38c1da28cff12a94ccfb82bbf6d8c11c033 | Ruby | Derikulous/interview_prep | /ruby/max_value.rb | UTF-8 | 1,304 | 4.4375 | 4 | [] | no_license | # 4) Your task is to
# • write a function that computes the maximum value among the deviations of all the sequences considered above
# • print the value the standard output (stdout)
# Note that your function will receive the following arguments:
# • v
# o which is the array of integers
# • d
# o which is an integer val... | true |
d0107fa9882c2014ca4c29b1b925fa55cfaf4811 | Ruby | mudasobwa/profigure | /lib/profigure.rb | UTF-8 | 4,339 | 3.234375 | 3 | [
"MIT"
] | permissive | require 'profigure/version'
require 'hash_deep_merge'
# @author Alexei Matyushkin
#
# Module to use as is, to monkeypatch it, or to extend in order to have
# nice and easy config files support.
#
# It’s designed to be as intuitive as possible.
#
# _Usages:_
#
# Say, we have the following `config.yml` file:
#
# :... | true |
52fb375bee18bcbb76a9264915a3804188cb5520 | Ruby | ymdelgado/ruby-gol | /Player.rb | UTF-8 | 1,926 | 3.5 | 4 | [] | no_license | require_relative 'Cell'
require_relative 'Grid'
class Player
attr_accessor :timeinterval
attr_accessor :rows, :cols
attr_reader :grid
attr_accessor :actions
def initialize
@rows, @cols= 10, 10
@timeinterval= 1
self.menu_actions
end
def menu_actions
system('clear')
#STDOUT.flush
... | true |
51dd053549734ec8da2ac46c57bb5dbe71701e7b | Ruby | sogilis/csv_fast_importer | /rakelib/release.rb | UTF-8 | 1,392 | 2.703125 | 3 | [
"MIT"
] | permissive | require './rakelib/repository'
require './rakelib/changelog'
class Release
GEM_NAME = 'csv_fast_importer'
VERSION_FILE = 'lib/csv_fast_importer/version.rb'
GEMFILE_LOCK = 'Gemfile.lock'
def initialize(type)
@type = type
end
def last_version
CSVFastImporter::VERSION
end
def version
@vers... | true |
aa4b98e10614680da71e0dd6f429c26f03475474 | Ruby | grosscol/auto_toggl | /lib/backfill.rb | UTF-8 | 1,581 | 2.65625 | 3 | [] | no_license | require 'togglv8'
require 'date'
require 'yaml'
require 'pry'
# Read the config
cfg = YAML.load_file('./config/auto_toggl.yml')
api_token = cfg["api_token"]
default_workspace_id = cfg["default_workspace_id"]
proj_id=cfg["default_project_id"]
# Have token or die
abort("no api_token") unless api_token
# Configure the... | true |
a2cdbfa759eee9d805d90f47902cd2be09283c7d | Ruby | notnotdrew/project-euler-multiples-3-5-web-0715-public | /lib/oo_multiples.rb | UTF-8 | 341 | 3.5 | 4 | [] | no_license | class Multiples
attr_reader :limit
def initialize(limit)
@limit = limit
end
def collect_multiples
(1...limit).select { |n| multiple_of?([3, 5], n) }
end
def sum_multiples
collect_multiples.reduce(&:+)
end
private
def multiple_of?(divisors, candidate)
divisors.any? { |d| candidate ... | true |
98006b24282b2e4313140efd1e1e3cf744f1e878 | Ruby | Dudu197/figurinhas-copa-2018 | /app/models/calculate.rb | UTF-8 | 562 | 2.8125 | 3 | [] | no_license | class Calculate
include ActiveModel::Model
attr_accessor :repited_str, :needed_str, :to_send, :to_receive, :calculated
def calculate
self.to_send = []
self.to_receive = []
my_repited = Repited.pluck(:number)
my_needed = Needed.pluck(:number)
self.repited_str.split(",").each do |number|
... | true |
838aff9bc569a7f9179667a11697cdfc89530272 | Ruby | Ugats/Ruby-Practice | /chapter07a.rb | UTF-8 | 283 | 3.515625 | 4 | [] | no_license | # encoding: utf-8
arr = []
is_Enter = false
puts '好きな英単語を入力してください(いくつでも)'
while is_Enter == false
word = gets.chomp
if word == ''
is_Enter = true
else
arr << word
end
end
sort_arr = arr.sort
sort_arr.each do |word|
puts word
end | true |
f6452504023dce12a1cd4f25b346aea8391e822d | Ruby | sebastianalamina/MyP_2020-1_Proyecto3 | /code/interfaz/TableroInterfaz.rb | UTF-8 | 685 | 3.09375 | 3 | [] | no_license | require_relative '../Tablero'
require_relative './CasillaInterfaz'
# Clase que representa un tablero en la interfaz.
class TableroInterfaz
attr_reader :casillas
# Inicializador de un tablero para la interfaz.
def initialize(tablero)
# Se asocia un tablero de ajedrez.
@tablero = tablero
# Se crea un ... | true |
bf3d6b379b3a99d20d036223d2cdaead851f3bf5 | Ruby | souleyman26/nouveau | /exo_05.rb | UTF-8 | 764 | 3.828125 | 4 | [] | no_license | puts "On va compter le nombre d'heures de travail à THP"
puts "Travail : #{10 * 5 * 11}"#multiplie entre
puts "En minutes ça fait : #{10 * 5 * 11 * 60}"# multiplie entre tjrs
puts "Et en secondes ?"
puts 10 * 5 * 11 * 60 * 60 # c'est un resultat
puts "Est-ce que c'est vrai que 3 + 2 < 5 - 7 ?" # boléen
puts 3 + 2 <... | true |
c65ee2c2a3dc5cb34a23d5d3cd26d152447d47b3 | Ruby | smunozmo/oop-school-library | /spec/solver_spec.rb | UTF-8 | 1,471 | 3.640625 | 4 | [] | no_license | require_relative '../solver'
describe 'Solver class' do
context 'Runing Solver' do
it 'Should the factorial of 5' do
solver = Solver.new
result = solver.factorial(5)
expect(result).to eq 120
end
it 'Should resturn 0' do
solver = Solver.new
result = solver.factorial(0)
... | true |
c674bbfc0f5516ee29bb2392fd377c139bd259c7 | Ruby | jbfolkerts/tablestakes | /lib/tablestakes.rb | UTF-8 | 24,035 | 3.671875 | 4 | [
"MIT"
] | permissive | #!/usr/bin/ruby -w
#
# Tablestakes is an implementation of a generic table class
# which takes input from a tab-delimited file and creates a
# generic table data structure that can be manipulated with
# methods similar to the way a database table may be manipulated.
#
# Author:: J.B. Folkerts (mailto:jbf@pentambic.com... | true |
85376a5413918636d89ce42bcd8fc6fe97856bbd | Ruby | OlegPerminov/parser | /product.rb | UTF-8 | 824 | 2.65625 | 3 | [] | no_license | require 'mechanize'
require 'securerandom'
class Product
def initialize(product, page)
@type = "product"
@name = product.at("a[@class='name']").text
@group_name = page.at("div[@id='tips']").text.split("/")[2]
@icon_name = SecureRandom.uuid + "." +
product.at("a[@class='img']")['rel']... | true |
55c9e889d80857558690b16947572ef26a390715 | Ruby | emmasroberts97/week_2_day_1_lab | /student.rb | UTF-8 | 557 | 3.59375 | 4 | [] | no_license | # PART A
class Student
def initialize(input_student, input_cohort)
@student = input_student
@cohort = input_cohort
end
#GETTERS
def student_name()
return @student
end
def cohort_name()
return @cohort
end
#SETTERS
def set_student_name(new_name)
@student = new_name
end
def ... | true |
7f73ec08889e5bb1ad2c3ac87060ab4cf97b0217 | Ruby | johnTheDudeMan/the_odin_project | /ruby_scripts/building_blocks/spec/caesar_cipher_spec.rb | UTF-8 | 828 | 3.0625 | 3 | [] | no_license | require_relative '../caesar_cipher'
describe "caesar_cipher" do
describe "takes string and integer parameter" do
let(:dbl) { double }
before { expect(dbl).to receive(:caesar_cipher).with(instance_of(String), instance_of(Fixnum)) }
it "passes when the args match" do
dbl.caesar_cipher("cat", 3)
end
end
... | true |
093e8e40624addbd5c28fb65e3e17180b9b6b32c | Ruby | jrodri207/parrot-ruby-online-web-pt-090919 | /parrot.rb | UTF-8 | 53 | 2.8125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def parrot(name = "Squawk!")
puts name
name
end
| true |
755bc2668bef654ba8fda5f632bb6b3c0a8d9d52 | Ruby | masayasviel/algorithmAndDataStructure | /from51to100/ABC93/mainB.rb | UTF-8 | 213 | 3.28125 | 3 | [] | no_license | a, b, k = gets.chomp.split(" ").map(&:to_i)
ans = []
if b-a+1 < k
ans = [*a..b]
else
a.upto(a+k-1) do |i|
ans << i
end
b.downto(b-k+1) do |i|
ans << i
end
end
puts ans.sort.uniq | true |
7badf899638a30748ab17bf7025803c4b56e96d5 | Ruby | miloprice/leetcode-review | /ruby/038_count_and_say.rb | UTF-8 | 655 | 3.84375 | 4 | [] | no_license | # @param {Integer} n
# @return {String}
# Faster than 53.33% of submissions
def count_and_say(n)
if n == 1
'1'
elsif n > 1
prev_val = count_and_say(n - 1)
cur_char = nil
cur_count = 0
cur_val = ""
prev_val.each_char.each do |new_char|
if cur_char && ne... | true |
d81ca084448fcc749d2e18d5d5f4610e4d84dd65 | Ruby | huberb/eulerproblems | /euler36/euler36.rb | UTF-8 | 395 | 3.890625 | 4 | [] | no_license | class Integer
def to_b
32.times
.map{ |i| self >> i & 1 == 1 ? "1" : "0" }
.reverse
.drop_while{ |b| b != "1" }
.join
end
end
def palindrom?(str)
(str.length / 2).times.all? do |i|
i2 = str.length - i - 1
str[i] == str[i2]
end
end
nums = 1_000_000
.times
.select{ |n| pa... | true |
96ea285f417ab2db76f2ccf331752c5acf6439e9 | Ruby | KamilLelonek/ruby-tuples | /spec/tuple_spec.rb | UTF-8 | 3,419 | 3.703125 | 4 | [] | no_license | describe Tuple do
describe 'Initialization' do
context 'initializer' do
it 'should instantiate with multiple arguments' do
expect { Tuple.new() } .not_to raise_error
expect { Tuple.new(1, 2, 3) }.not_to raise_error
expect(Tuple.new()) .to be_instance_of Tuple
exp... | true |
6468d17715a61d0fce58189fb9a90c9a8a8e5621 | Ruby | arfelio/one_way_ticket | /app/repos/repo.rb | UTF-8 | 571 | 2.609375 | 3 | [] | no_license | class Repo
def initialize(klass, params)
@params = params
@klass = klass
end
attr_reader :params, :klass
def create
klass.to_adapter.create!(params)
end
def find
klass.to_adapter.find_first(params)
end
def find_by_id
klass.to_adapter.get!(params)
end
def get_collection(args... | true |
7e2256d3787eb0294f5966fd16beab3371c48225 | Ruby | jelenicak/text-split | /lib/page.rb | UTF-8 | 814 | 2.953125 | 3 | [] | no_license | require "open-uri"
require_relative "exceptions"
class Page
LOOKS_LIKE_XPATH = /^(\.\/|\/|\.\.|\.$)/
# this regular expression can be found in
# Nokogiri::XML::Searchable
def self.extract(url, xpath)
new(url, xpath)
end
def initialize(url, xpath)
@doc = Nokogiri::HTML(open(url).read)
@xpath ... | true |
55836dcbec282a07fd3c93b143070d60ddd2961d | Ruby | XRayV5/tribe_marketplace- | /spec/model.spec.rb | UTF-8 | 4,458 | 2.828125 | 3 | [] | no_license | require "spec_helper"
describe Bundle do
describe ".initialize" do
it "generates the bundle instance with format of IMG" do
expect(Bundle.new("IMG").get_format).to eq "IMG"
end
it "generates the bundle instance with format of Flac" do
expect(Bundle.new("Flac").get_format).to eq "Flac"
... | true |
6f75b7f843e7301f025b0d6ed1f6d834cc6b6a39 | Ruby | Cileos/shiftplan | /app/models/time_period_formatter.rb | UTF-8 | 2,074 | 3.203125 | 3 | [] | no_license | # Basically a model-layer decorator
module TimePeriodFormatter
def self.period_with_zeros(from, to)
[time_with_zeros(from), time_with_zeros(to)].compact.join('-')
end
def self.period_without_zeros(from, to)
[time_without_zeros(from), time_without_zeros(to)].compact.join('-')
end
# show zeros only if... | true |
d77971132fba30e3fa4bfcf98f0230edfdadb150 | Ruby | MaligneCanyon/programming_foundations | /exercises/easy2_ex6.rb | UTF-8 | 328 | 3.515625 | 4 | [] | no_license | # inputs:
# - none
# outputs:
# - odd numbers, each printed on a separate line
# reqs:
# - print all odd nums btwn 1 and 99
# rules:
# - print each num on a sep line
# struct:
# -numeric
# algo:
# - from 1 to 99
# - print the num
# - incr by 2
1.step(by:2, to:99) { |num| puts num }
# (1..99).each { |v| puts v if v... | true |
2e49a2a56531e2e0df6fe3aa25f2373a892c330d | Ruby | Vidreven/rubitcointools | /lib/blocks.rb | UTF-8 | 2,306 | 3.09375 | 3 | [
"MIT"
] | permissive | require_relative 'specials'
require_relative 'hashes'
class Blocks
def initialize
@sp = Specials.new
@h = Hashes.new
end
def serialize_header(inp)
o = @sp.change_endianness(inp[:version]) +
@sp.change_endianness(inp[:prevhash]) +
@sp.change_endianness(inp[:merkle_root]) +
@sp.change... | true |
e4eef695a9df8fb6f5211458f9e1249a821b7f35 | Ruby | BrunoJimenezUrizar/devmemo | /test/unit/dump_test.rb | UTF-8 | 1,654 | 2.578125 | 3 | [] | no_license | require 'test_helper'
class DumpTest < ActiveSupport::TestCase
#### UT_032W ##############################################
test "dump_create" do
assert Dump.create, "UT_032W: dump should be created"
end
##########################################################
#### UT_033W ##################################... | true |
453ecebc13ac3edf40c3cb412cda192b5f60c75e | Ruby | wbailey/data_table | /lib/data_table/row.rb | UTF-8 | 1,229 | 2.875 | 3 | [] | no_license | class DataTable
def add_row( row, options = { :after => :last } )
raise UndefinedHeader unless valid_header?
raise InvalidRow unless row.is_a?( Array )
raise InvalidRowSize unless row.size.eql?( @header.size )
raise InvalidAddOption unless options.is_a?( Hash ) && options.keys.size.eql?( 1 )
orde... | true |
1c68d62765d45e343b4595ab359eba6abb0baf58 | Ruby | proudcloudojt/sample_app | /app/models/micropost.rb | UTF-8 | 1,217 | 2.546875 | 3 | [] | no_license | class Micropost < ActiveRecord::Base
attr_accessible :content , :recipients
USERNAME_REGEX = /@\w+/i
belongs_to :user
has_many :recipients, :dependent => :destroy
has_many :replied_users, :through => :recipients, :source => "user"
validates :content, :presence => true, :length => { :maximum => 140 }
... | true |
23e29603122fbe2ccacf9f26fdc4165f046b8275 | Ruby | Sifuri/TicTacToe | /gameboard.rb | UTF-8 | 1,246 | 3.875 | 4 | [] | no_license | # GameBoard Class
class GameBoard
attr_accessor :options
# Represent a new board with an array of numerical elements for each board space.
def initialize
@options = []
SPACES.times do |s|
options << s
end
end
#Display the current board.
def show(new_options = nil)
@options = new... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.