source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli.rb | Ruby | mit | 308 | master | 1,033 | module Mogli
end
require "httparty"
require "httmultiparty"
require "mogli/authenticator"
require "mogli/model"
require "mogli/profile"
require "mogli/fetching_array"
require "mogli/action"
require "mogli/activity"
require "mogli/address"
require "mogli/album"
require "mogli/application"
require "mogli/app_request"
r... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/group.rb | Ruby | mit | 308 | master | 374 | module Mogli
class Group < Model
set_search_type
define_properties :id, :name, :description, :link, :privacy,
:updated_time, :version, :administrator, :unread, :bookmark_order
hash_populating_accessor :owner, "User", "Page"
hash_populating_accessor :venue, "Address"
has_association :feed, ... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/user.rb | Ruby | mit | 308 | master | 4,261 | module Mogli
class User < Profile
set_search_type
define_properties :username, :first_name, :last_name, :link, :about, :birthday, :gender,
:email, :website, :timezone, :updated_time, :verified, :political, :bio,
:interested_in, :relationship_status, :locale, :religion, :quotes, :third_par... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/test_user.rb | Ruby | mit | 308 | master | 1,566 | module Mogli
# Support for Facebook test users, as described here:
#
# http://developers.facebook.com/docs/test_users/
#
# Test user creation/listing requires an app access token and an app
# id.
#
# Example usage:
#
# +Mogli::TestUser.all({}, Mogli::AppClient.new('access_token', 'app_id'))+
class... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/work.rb | Ruby | mit | 308 | master | 314 | module Mogli
class Work < Model
define_properties :start_date, :end_date, :description, :with, :from
hash_populating_accessor :projects, "Page"
hash_populating_accessor :employer, "Page"
hash_populating_accessor :location, "Page"
hash_populating_accessor :position, "Page"
end
end |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/status.rb | Ruby | mit | 308 | master | 250 | module Mogli
class Status < Model
define_properties :id, :message, :updated_time, :created_time, :likes
hash_populating_accessor :from, "User", "Page"
has_association :comments, "Comment"
has_association :place, "Place"
end
end |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/event.rb | Ruby | mit | 308 | master | 629 | module Mogli
class Event < Model
set_search_type
define_properties :id, :name, :description, :start_time, :end_time, :location, :privacy, :updated_time, :rsvp_status, :timezone
creation_properties :start_time, :end_time, :link, :name, :description, :privacy
hash_populating_accessor :venue, "Address"
... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/album.rb | Ruby | mit | 308 | master | 373 | module Mogli
class Album < Model
define_properties :id, :name, :description, :location, :cover_photo, :privacy, :link, :count, :created_time, :updated_time,
:likes, :can_upload
creation_properties :name, :description
hash_populating_accessor :from, "User","Page"
has_association :photos, "Photo"... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/comment.rb | Ruby | mit | 308 | master | 253 | module Mogli
class Comment < Model
define_properties :id, :message, :created_time, :count, :likes, :can_remove, :message_tags, :user_likes, :like_count
creation_properties :message
hash_populating_accessor :from, "User","Page"
end
end |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/action.rb | Ruby | mit | 308 | master | 349 | module Mogli
class Action < Model
define_properties :name, :link
# simple implementation of to_json, ignoring options like :only, :except,
# :include, :methods because this is primarily intended for being submitted
# to facebook
def to_json(options = nil)
"{\"name\":\"#{name}\",\"link\":\"#... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/permissions.rb | Ruby | mit | 308 | master | 1,681 | module Mogli
class Permissions < Model
define_properties \
:user_about_me,
:user_activities,
:user_birthday,
:user_checkins,
:user_education_history,
:user_events,
:user_games_activity,
:user_groups,
:user_hometown,
:user_interests,
:user_likes,
:user_location,... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/fetching_array.rb | Ruby | mit | 308 | master | 605 | module Mogli
class FetchingArray < Array
attr_accessor :next_url, :previous_url, :client, :classes, :total_count
def fetch_next
return [] if next_url.nil? || next_url.empty?
additions = client.get_and_map_url(next_url,classes)
self.next_url = additions.next_url
self.concat(additions)
... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/fql_multiquery.rb | Ruby | mit | 308 | master | 1,374 | module Mogli
class FqlMultiquery
attr_reader :client, :queries, :raw_response
# Takes Mogli::Client object
def initialize(client)
@client = client
@queries = {}
end
# Adds single query to multiquery with class used to populate results
def add_named_query_for_class(quer... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/checkin.rb | Ruby | mit | 308 | master | 296 | module Mogli
class Checkin < Model
define_properties :id,:message, :created_time, :likes, :comments
hash_populating_accessor :from, "User"
hash_populating_accessor :tags, "User"
hash_populating_accessor :place, "Page"
hash_populating_accessor :application, "Page"
end
end |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/post.rb | Ruby | mit | 308 | master | 689 | require 'multi_json'
require 'json'
module Mogli
class Post < Model
define_properties :id, :from, :to, :story, :message, :picture, :link, :name, :caption,
:description, :source, :icon, :attribution, :actions, :likes,
:created_time, :updated_time, :privacy, :type, :object_id, :properties
creatio... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/authenticator.rb | Ruby | mit | 308 | master | 2,387 | require "cgi"
require 'mogli/client'
module Mogli
class Authenticator
attr_reader :client_id, :secret, :callback_url
def initialize(client_id,secret,callback_url)
@client_id = client_id
@secret = secret
@callback_url = callback_url
end
def authorize_url(options = {})
options... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/page.rb | Ruby | mit | 308 | master | 1,043 | module Mogli
class Page < Profile
set_search_type
define_properties :id, :name, :category, :username, :access_token, :namespace
# General
define_properties :likes, :link, :picture, :has_added_app, :website, :description, :can_post, :checkins, :general_info
# Retail
define_properties :founde... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/link.rb | Ruby | mit | 308 | master | 312 | module Mogli
class Link < Model
define_properties :link, :message, :id, :name, :page, :created_time, :updated_time,
:icon, :picture, :description, :caption
creation_properties :link, :message
hash_populating_accessor :comments, "Comment"
hash_populating_accessor :from, "User"
end
end |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/profile.rb | Ruby | mit | 308 | master | 1,278 | module Mogli
class Profile < Model
define_properties :id, :name
has_association :feed, "Post"
has_association :links, "Link"
has_association :photos, "Photo"
has_association :groups, "Group"
has_association :albums,"Album"
has_association :videos, "Video"
has_association :notes, "Note... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/app_client.rb | Ruby | mit | 308 | master | 951 | require "mogli/client/event"
require "mogli/client/user"
module Mogli
class AppClient < Client
attr_accessor :application_id
def initialize(app_token, application_id=nil)
super(app_token)
self.application_id = application_id
end
def subscription_url
"https://graph.facebook... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/app_request.rb | Ruby | mit | 308 | master | 264 | module Mogli
class AppRequest < Model
define_properties :id, :data, :message, :created_time
hash_populating_accessor :application, "Application"
hash_populating_accessor :from, "Profile"
hash_populating_accessor :to, "Profile"
end
end |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/friendlist.rb | Ruby | mit | 308 | master | 243 | module Mogli
# requires read_friendlists permission
# https://developers.facebook.com/docs/reference/api/FriendList/
class FriendList < Model
define_properties :name, :list_type, :id
has_association :members, "User"
end
end |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/video.rb | Ruby | mit | 308 | master | 307 | module Mogli
class Video < Model
define_properties :id, :message, :name, :description, :length, :created_time,
:updated_time, :icon, :picture, :embed_html, :caption, :link, :source, :likes
hash_populating_accessor :from, "User", "Page"
has_association :comments, "Comment"
end
end |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/application.rb | Ruby | mit | 308 | master | 395 | module Mogli
class Application < Model
define_properties :id, :name, :description, :category, :subcategory, :link, :canvas_name, :namespace, :icon_url, :logo_url, :weekly_active_users, :monthly_active_users, :daily_active_users
has_association :feed, "Post"
has_association :posts, "Post"
has_associa... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/model.rb | Ruby | mit | 308 | master | 5,162 | require 'mogli/model/search'
module Mogli
class Model
extend Mogli::Model::Search
set_search_type :all
attr_accessor :type
def client=(val)
@client=val
end
def client
@client || Mogli::Client.new
end
def initialize(hash={},client=nil)
@_values = {}
self.... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/note.rb | Ruby | mit | 308 | master | 281 | module Mogli
class Note < Model
define_properties :id, :subject, :message, :created_time, :updated_time, :icon
creation_properties :message, :subject
hash_populating_accessor :from, "User", "Page"
has_association :comments, "Comment"
end
end |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/client.rb | Ruby | mit | 308 | master | 9,550 | require "mogli/client/event"
require "mogli/client/user"
module Mogli
class Client
attr_reader :access_token
attr_reader :default_params
attr_reader :expiration
include HTTMultiParty
include Mogli::Client::Event
include Mogli::Client::User
headers 'Accept' => "*/*", 'Content-Type' => "*... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/education.rb | Ruby | mit | 308 | master | 298 | module Mogli
class Education < Model
define_properties :start_date, :end_date, :degree, :with
hash_populating_accessor :classes, "Page"
hash_populating_accessor :school, "Page"
hash_populating_accessor :year, "Page"
hash_populating_accessor :concentration, "Page"
end
end |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/place.rb | Ruby | mit | 308 | master | 1,578 | module Mogli
class Place < Model
define_properties :id, :name, :category, :username, :can_post, :phone, :website, :checkins, :link, :public_transit, :likes, :picture
hash_populating_accessor_with_default_field :location, "street", "Address"
hash_populating_accessor :restaurant_services, "RestaurantSe... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/photo.rb | Ruby | mit | 308 | master | 359 | module Mogli
class Photo < Model
define_properties :id, :name, :tags, :picture, :source, :height, :width, :images, :link, :icon,
:created_time, :updated_time, :position, :comments, :likes, :place, :name_tags
creation_properties :message
hash_populating_accessor :from, "User","Page"
hash_populat... |
github | mmangino/mogli | https://github.com/mmangino/mogli | lib/mogli/model/search.rb | Ruby | mit | 308 | master | 572 | module Mogli
class Model
module Search
attr_reader :search_type
def search(pattern="", client=nil, args={})
raise(NoMethodError.new("Can't search for #{self.to_s}")) unless search_type
args.merge!({:q => pattern})
args.merge!(:type => self.search_type) unless search_type == 'a... |
github | mkocher/soloist | https://github.com/mkocher/soloist | Vagrantfile | Ruby | mit | 308 | master | 825 | #!/usr/bin/env ruby
Vagrant::Config.run do |config|
ssh_key = File.read(File.expand_path("~/.ssh/id_rsa.pub"))
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/#{config.vm.box}.box"
config.vm.network :hostonly, "192.168.6.66"
config.vm.provision :shell, :inline => "test -d /etc/s... |
github | mkocher/soloist | https://github.com/mkocher/soloist | soloist.gemspec | Ruby | mit | 308 | master | 1,557 | # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "soloist/version"
Gem::Specification.new do |s|
s.name = "soloist"
s.version = Soloist::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Matthew Kocher", "Doc Ritezel"]
s.email = ["kocher@gmail.com", ... |
github | mkocher/soloist | https://github.com/mkocher/soloist | Guardfile | Ruby | mit | 308 | master | 465 | #!/usr/bin/env ruby
guard 'rspec', :cli => '--fail-fast --tag ~@slow:true' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
guard 'bundler' do
watch('Gemfile')
watch('soloist.gemspec')
end
guard 'shell' do
watch... |
github | mkocher/soloist | https://github.com/mkocher/soloist | spec/spec_helper.rb | Ruby | mit | 308 | master | 458 | $: << File.expand_path("../../lib", __FILE__)
require "soloist"
require "tempfile"
require "json"
require "tmpdir"
require "net/ssh/test"
Dir.glob(File.expand_path("../helpers/**/*.rb", __FILE__)) { |f| require f }
RSpec.configure do |config|
config.add_setting :tempdir
config.before(:each) { RSpec.configuration... |
github | mkocher/soloist | https://github.com/mkocher/soloist | spec/helpers/net_ssh_test_patch.rb | Ruby | mit | 308 | master | 1,014 | require "net/ssh/test"
class Net::SSH::Test::Packet
alias :original_types :types
def types
@types ||= case @type
when CHANNEL_EXTENDED_DATA then [:long, :long, :string]
else original_types
end
end
end
class Net::SSH::Test::Script
def gets_channel_extended_data(channel, data)
events <... |
github | mkocher/soloist | https://github.com/mkocher/soloist | spec/lib/soloist/config_spec.rb | Ruby | mit | 308 | master | 7,040 | require "spec_helper"
RSpec.describe Soloist::Config do
let(:soloist_rc_path) { File.expand_path("soloistrc", RSpec.configuration.tempdir) }
let(:soloist_rc) { Soloist::RoyalCrown.new(:path => soloist_rc_path) }
let(:config) { Soloist::Config.new(soloist_rc) }
let(:cookbook_path) { File.expand_path("cookbooks"... |
github | mkocher/soloist | https://github.com/mkocher/soloist | spec/lib/soloist/royal_crown_spec.rb | Ruby | mit | 308 | master | 2,007 | require "spec_helper"
RSpec.describe Soloist::RoyalCrown do
let(:contents) { { "recipes" => ["broken_vim"] } }
let(:tempfile) do
Tempfile.new("soloist-royalcrown").tap do |file|
file.write(YAML.dump(contents))
file.close
end
end
let(:royal_crown) { Soloist::RoyalCrown.from_file(tempfile.pa... |
github | mkocher/soloist | https://github.com/mkocher/soloist | spec/lib/soloist/spotlight_spec.rb | Ruby | mit | 308 | master | 1,984 | require "spec_helper"
RSpec.describe Soloist::Spotlight do
let(:shallow_path) { File.expand_path("beans/roger", RSpec.configuration.tempdir) }
let(:spotlight) { Soloist::Spotlight.new(shallow_path) }
before { FileUtils.mkdir_p(shallow_path) }
describe "#find" do
context "with non-existent files" do
... |
github | mkocher/soloist | https://github.com/mkocher/soloist | spec/lib/soloist/remote_spec.rb | Ruby | mit | 308 | master | 4,407 | require "spec_helper"
RSpec.describe Soloist::Remote do
include Net::SSH::Test
subject { Soloist::Remote.new("user", "host", "key") }
before { subject.connection = connection }
shared_examples "ssh exec" do |command|
let(:stdio) { double(:stdio, :<< => nil) }
before { allow(subject).to receive_mess... |
github | mkocher/soloist | https://github.com/mkocher/soloist | spec/lib/soloist/cli_spec.rb | Ruby | mit | 308 | master | 4,832 | require "spec_helper"
RSpec.describe Soloist::CLI do
let(:cli) { Soloist::CLI.new }
let(:base_path) { RSpec.configuration.tempdir }
let(:soloistrc_path) { File.expand_path("soloistrc", base_path) }
before do
FileUtils.mkdir_p(base_path)
allow_any_instance_of(Soloist::Config).to receive(:exec)
end
... |
github | mkocher/soloist | https://github.com/mkocher/soloist | spec/lib/soloist/remote_config_spec.rb | Ruby | mit | 308 | master | 2,570 | require "spec_helper"
RSpec.describe Soloist::RemoteConfig do
let(:royal_crown_path) { File.expand_path("soloistrc", RSpec.configuration.tempdir) }
let(:royal_crown) { Soloist::RoyalCrown.new(:path => royal_crown_path) }
let(:remote) { Soloist::Remote.new("user", "host", "key") }
let(:remote_config) { Soloist:... |
github | mkocher/soloist | https://github.com/mkocher/soloist | examples/Guardfile | Ruby | mit | 308 | master | 438 | #!/usr/bin/env ruby
guard 'bundler' do
watch('../Gemfile')
watch('../soloist.gemspec')
end
guard 'shell' do
watch('soloistrc') { system("../bin/soloist -r 192.168.6.66") }
watch(%r{^cookbooks/(.+)\.rb$}) { system("unset RUBYOPT; bundle exec ../bin/soloist -r 192.168.6.66") }
watch('Vagrantfile') { system("u... |
github | mkocher/soloist | https://github.com/mkocher/soloist | lib/soloist/spotlight.rb | Ruby | mit | 308 | master | 907 | require 'pathname'
module Soloist
class NotFound < RuntimeError; end
class Spotlight
attr_reader :pathname
def self.find(*file_names)
new(Dir.pwd).find(*file_names)
end
def self.find!(*file_names)
new(Dir.pwd).find!(*file_names)
end
def initialize(path)
@pathname = Pat... |
github | mkocher/soloist | https://github.com/mkocher/soloist | lib/soloist/royal_crown.rb | Ruby | mit | 308 | master | 2,241 | require "hashie"
module Soloist
class RoyalCrown < Hashie::Trash
property :path
property :recipes, :default => []
property :cookbook_paths, :default => []
property :node_attributes, :default => Hashie::Mash.new,
:transform_with => lambda { |v| Hashie::Mash.new(v) }
property :env_vari... |
github | mkocher/soloist | https://github.com/mkocher/soloist | lib/soloist/config.rb | Ruby | mit | 308 | master | 2,853 | require "soloist/royal_crown"
require "tempfile"
module Soloist
class Config
attr_writer :solo_rb_path, :node_json_path
attr_reader :royal_crown
def self.from_file(royal_crown_path)
rc = Soloist::RoyalCrown.from_file(royal_crown_path)
new(rc)
end
def initialize(royal_crown)
@r... |
github | mkocher/soloist | https://github.com/mkocher/soloist | lib/soloist/cli.rb | Ruby | mit | 308 | master | 2,103 | require "librarian/chef/cli"
require "soloist/remote_config"
require "soloist/spotlight"
require "awesome_print"
require "thor"
module Soloist
class CLI < Thor
attr_writer :soloist_config
default_task :chef
desc "chef", "Run chef-solo"
method_option :remote, :aliases => "-r", :desc => "Run chef-solo... |
github | mkocher/soloist | https://github.com/mkocher/soloist | lib/soloist/remote_config.rb | Ruby | mit | 308 | master | 1,691 | require "soloist/config"
require "soloist/remote"
module Soloist
class RemoteConfig < Config
attr_reader :remote
def self.from_file(royal_crown_path, remote)
rc = Soloist::RoyalCrown.from_file(royal_crown_path)
new(rc, remote)
end
def initialize(royal_crown, remote)
@royal_crown =... |
github | mkocher/soloist | https://github.com/mkocher/soloist | lib/soloist/remote.rb | Ruby | mit | 308 | master | 1,743 | require "net/ssh"
require "shellwords"
require "etc"
module Soloist
class RemoteError < RuntimeError; end
class Remote
attr_reader :user, :host, :key, :timeout, :stdout, :stderr, :exitstatus
attr_writer :connection
def self.from_uri(uri, key = "~/.ssh/id_rsa")
parsed = URI.parse("ssh://#{uri}")... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/9_debugging/exercises/debugging_exercises.rb | Ruby | mit | 308 | main | 1,918 | require 'pry-byebug'
# First, we're going to practice reading the Stack Trace
# Don't look at this method prior to running the test
# Type 'rspec' into the terminal to run Rspec
# Once this test fails, have a look at the Stack Trace
# Try to see if you can work your way from the last line, the bottom of the stack
# To... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/9_debugging/spec/spec_helper.rb | Ruby | mit | 308 | main | 448 | RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.shared_context_metadata_behavior = :apply_to_host_groups
end
module... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/9_debugging/spec/debugging_exercises_spec.rb | Ruby | mit | 308 | main | 1,309 | require 'spec_helper'
require_relative '../exercises/debugging_exercises'
RSpec.describe 'Debugging Exercises' do
describe 'decrement_smallest_value' do
# remove the 'x' from the line below to unskip the test
it 'Returns 0 after you use the stack trace to find and fix the error' do
nested_array = [[3,... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/11_predicate_enumerables/spec/predicate_enumerable_exercises_spec.rb | Ruby | mit | 308 | main | 3,247 | require 'spec_helper'
require_relative '../exercises/predicate_enumerable_exercises'
RSpec.describe 'Predicate Enumerable Exercises' do
describe 'coffee drink exercise' do
it 'returns true when coffee is included' do
drink_list = ["coffee", "water", "tea"]
expect(coffee_drink?(drink_list)).to be tr... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/11_predicate_enumerables/spec/spec_helper.rb | Ruby | mit | 308 | main | 447 | RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.shared_context_metadata_behavior = :apply_to_host_groups
end
module ... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/11_predicate_enumerables/exercises/predicate_enumerable_exercises.rb | Ruby | mit | 308 | main | 977 | def coffee_drink?(drink_list)
# use #include? to return true when the drink_list (array) contains the string "coffee" or "espresso"
drink_list.include?("coffee") || drink_list.include?("espresso")
end
def correct_guess?(guess_list, answer)
# use #any? to return true when any element of the guess_list (array) equ... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/8_methods/exercises/method_exercises.rb | Ruby | mit | 308 | main | 2,220 | # Since lesson #8 is on methods, you will be writing the entire method.
# To gain more familiarity, look up the documentation for each hint.
# Remember to unskip the corresponding tests one at a time.
# method name: #ascii_translator
# parameter: number (an integer)
# return value: the number's ASCII character (https:... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/8_methods/spec/method_exercises_spec.rb | Ruby | mit | 308 | main | 3,529 | require 'spec_helper'
require_relative '../exercises/method_exercises'
RSpec.describe 'Method Exercises' do
describe 'ASCII translator exercise using #chr' do
it 'returns an uppercase A' do
expect(ascii_translator(65)).to eq('A')
end
# remove the 'x' from the line below to unskip the test
it... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/6_arrays/spec/array_exercises_spec.rb | Ruby | mit | 308 | main | 4,633 | require 'spec_helper'
require_relative '../exercises/array_exercises'
RSpec.describe 'Array Exercises' do
describe 'nil array exercise' do
it 'returns an array containing 5 nil values' do
expect(nil_array(5)).to eq([nil, nil, nil, nil, nil])
end
# remove the 'x' from the line below to unskip the ... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/6_arrays/exercises/array_exercises.rb | Ruby | mit | 308 | main | 1,632 | def nil_array(number)
# return an array containing `nil` the given number of times
Array.new(number)
end
def first_element(array)
# return the first element of the array
array.first
end
def third_element(array)
# return the third element of the array
array[2]
end
def last_three_elements(array)
# return... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/10_basic_enumerables/exercises/basic_enumerable_exercises.rb | Ruby | mit | 308 | main | 1,557 | def display_current_inventory(inventory_list)
# use #each to iterate through each item of the inventory_list (a hash)
# use puts to output each list item "<key>, quantity: <value>" to console
inventory_list.each do |key, value|
puts "#{key}, quantity: #{value}"
end
end
def display_guess_order(guesses)
# ... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/10_basic_enumerables/spec/basic_enumerable_exercises_spec.rb | Ruby | mit | 308 | main | 3,023 | require 'spec_helper'
require_relative '../exercises/basic_enumerable_exercises'
RSpec.describe 'Basic Enumerable Exercises' do
describe 'display current inventory exercise' do
it 'outputs each inventory item' do
expect($stdout).to receive(:puts).with("apples, quantity: 1")
expect($stdout).to recei... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/1_data_types/exercises/numbers_exercises.rb | Ruby | mit | 308 | main | 845 | def add(a, b)
# return the result of adding a and b
a + b
end
def subtract(a, b)
# return the result of subtracting b from a
a - b
end
def multiply(a, b)
# return the result of multiplying a times b
a * b
end
def divide(a, b)
# return the result of dividing a by b
a / b
end
def remainder(a, b)
# r... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/1_data_types/exercises/string_exercises.rb | Ruby | mit | 308 | main | 982 | def concatenate_example(string)
# use concatenation to format the result to be "Classic <string>"
"Classic " + string
end
def concatenate(string)
# use concatenation to format the result to be "Hello <string>!"
"Hello " + string + "!"
end
def substrings(word)
# return the first 4 letters from the word using... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/1_data_types/spec/strings_exercises_spec.rb | Ruby | mit | 308 | main | 2,590 | require 'spec_helper'
require_relative '../exercises/string_exercises'
RSpec.describe 'String Exercises' do
describe 'concatenation example exercise' do
it 'returns "Classic Ruby"' do
expect(concatenate_example('Ruby')).to eq('Classic Ruby')
end
end
describe 'concatenation exercise' do
it '... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/1_data_types/spec/numbers_exercises_spec.rb | Ruby | mit | 308 | main | 1,825 | require 'spec_helper'
require_relative '../exercises/numbers_exercises'
RSpec.describe 'Numbers Exercises' do
describe 'addition exercise' do
it 'adds two positive numbers' do
expect(add(1, 2)).to eq(3)
end
it 'adds two negative numbers' do
expect(add(-2, -3)).to eq(-5)
end
end
de... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/7_hashes/exercises/hash_exercises.rb | Ruby | mit | 308 | main | 1,331 | def create_favorite_hash(color, number)
# return a hash with the following key/value pairs:
# key of color (as a symbol) with value of the color argument
# key of number (as a symbol) with the value of the number argument
{ color: color, number: number }
end
def favorite_color(favorite_list)
# return the val... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/7_hashes/spec/hash_exercises_spec.rb | Ruby | mit | 308 | main | 5,201 | require 'spec_helper'
require_relative '../exercises/hash_exercises'
RSpec.describe 'Hash Exercises' do
describe 'create favorite hash exercise' do
it 'returns result with a string and integer' do
favorite = create_favorite_hash('blue', 65)
result = { color: 'blue', number: 65 }
expect(favorit... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/12_nested_collections/exercises/nested_hash_exercises.rb | Ruby | mit | 308 | main | 2,425 | def find_language_information(languages, language_name)
# Take languages (a nested hash) and language_name as a symbol, return the
# value for the language_name key (which will be another hash!)
# the languages hash will look something like this:
# {
# ruby: { initial_release: 'December 25, 1996', is_beaut... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/12_nested_collections/exercises/nested_array_exercises.rb | Ruby | mit | 308 | main | 2,191 | def blank_seating_chart(number_of_rows, seats_per_row)
# return a 2d array to represent a seating chart that contains
# number_of_rows nested arrays, each with seats_per_row entries of nil to
# represent that each seat is empty.
# Example: blank_seating_chart(2, 3) should return:
# [
# [nil, nil, nil],
... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/12_nested_collections/spec/nested_array_exercises_spec.rb | Ruby | mit | 308 | main | 4,748 | require 'spec_helper'
require_relative '../exercises/nested_array_exercises'
RSpec.describe 'Nested Array Exercises' do
describe 'blank seating chart creation exercise' do
it 'returns a 2d array (chart) containing 2 rows, each containing nil 3 times' do
expected_output = [[nil, nil, nil], [nil, nil, nil]]
... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/ruby_basics/12_nested_collections/spec/nested_hash_exercises_spec.rb | Ruby | mit | 308 | main | 7,339 | require 'spec_helper'
require_relative '../exercises/nested_hash_exercises'
RSpec.describe 'Nested hash exercises' do
describe 'find language information exercise' do
let(:hash) do
{
ruby: { initial_release: 'December 25, 1996', is_beautiful?: true },
javascript: { initial_release: 'Decembe... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/recursion/4_permutations/spec/permutations_spec.rb | Ruby | mit | 308 | main | 1,177 | require 'spec_helper'
require_relative '../exercises/permutation_exercises'
RSpec.describe '#permutations' do
it "returns 1 possible permutation for a set containing 0 numbers" do
expect(permutations([])).to eq [[]]
end
it "returns 2 possible permutations for a set containing 2 numbers" do
expect(permut... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/recursion/4_permutations/exercises/permutation_exercises.rb | Ruby | mit | 308 | main | 304 | def permutations(array, index = 0, results = [])
results << array.dup if index == array.length
(index...array.length).each do |i|
array[index], array[i] = array[i], array[index]
permutations(array, index + 1, results)
array[index], array[i] = array[i], array[index]
end
results
end |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/recursion/1_factorial/spec/factorial_spec.rb | Ruby | mit | 308 | main | 624 | require "spec_helper"
require_relative "../exercises/factorial"
RSpec.describe "Factorial" do
describe "factorial exercise" do
it "returns 1 when passed the number 1" do
expect(factorial(1)).to eq(1)
end
it "returns 24 when passed the number 4" do
expect(factorial(4)).to eq(24)
end
... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/recursion/1_factorial/exercises/factorial.rb | Ruby | mit | 308 | main | 218 | def factorial(num)
# write a recursive method for calculating the [factorial](https://simple.wikipedia.org/wiki/Factorial) of a number
return if num.negative?
return 1 if num <= 1
num * factorial(num - 1)
end |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/recursion/3_total_integers/spec/total_integers_exercises_spec.rb | Ruby | mit | 308 | main | 1,922 | require 'spec_helper'
require_relative '../exercises/total_integers_exercises'
RSpec.describe '#total_integers' do
# This shared context ensures that the solution uses recursion
# and doesn't take a shortcut by using Array#flatten
shared_context 'array that should not use flatten' do
before do
allow(te... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/recursion/5_pascal/exercises/pascal_exercises.rb | Ruby | mit | 308 | main | 215 | def pascal(row_number)
current_line = [1]
return current_line if row_number == 1
previous_line = pascal(row_number - 1) + [0]
previous_line.each_cons(2) { |a, b| current_line << a + b }
current_line
end |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/recursion/5_pascal/spec/pascal_exercises_spec.rb | Ruby | mit | 308 | main | 819 | require 'spec_helper'
require_relative '../exercises/pascal_exercises'
RSpec.describe '#pascal' do
it 'gets the first row of the pascal triangle' do
expect(pascal(1)).to eq([1])
end
it 'gets the second row of the pascal triangle' do
expect(pascal(2)).to eq([1, 1])
end
it 'gets the third row of the ... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/recursion/2_contains/spec/contains_spec.rb | Ruby | mit | 308 | main | 1,233 | require_relative "../exercises/contains_exercises"
describe "#contains?" do
let(:nested_hash) do
{
data: {
duplicate: "e",
stuff: {
thing: {
banana: "banana",
more_stuff: {
something: "foo"
}
}
},
info: {
... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | solutions/recursion/2_contains/exercises/contains_exercises.rb | Ruby | mit | 308 | main | 248 | def contains?(hash, search_value)
values = hash.values
return true if values.include?(search_value)
nested_hashes = values.select { |value| value.is_a?(Hash) }
nested_hashes.any? { |nested_hash| contains?(nested_hash, search_value) }
end |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | generators/exercise_generator.rb | Ruby | mit | 308 | main | 1,565 | require "fileutils"
class ExerciseGenerator
def initialize(namespace, exercise_group_name, exercise_name)
@namespace = namespace
@exercise_group_name = exercise_group_name
@exercise_name = exercise_name
end
TEMPLATE_DIR_PATH = "generators/exercise_template".freeze
def generate
unless Dir.exis... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | generators/spec/spec_helper.rb | Ruby | mit | 308 | main | 4,733 | # This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
# file... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | generators/spec/exercise_generator_spec.rb | Ruby | mit | 308 | main | 3,131 | require_relative "../exercise_generator"
describe ExerciseGenerator do
describe "#generate" do
subject(:generator) { described_class.new("test_namespace", "1_test_group", "test_exercise") }
before do
allow(FileUtils).to receive(:mkdir_p)
allow(FileUtils).to receive(:copy_entry)
allow(FileU... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/12_nested_collections/exercises/nested_array_exercises.rb | Ruby | mit | 308 | main | 1,891 | def blank_seating_chart(number_of_rows, seats_per_row)
# return a 2d array to represent a seating chart that contains
# number_of_rows nested arrays, each with seats_per_row entries of nil to
# represent that each seat is empty.
# Example: blank_seating_chart(2, 3) should return:
# [
# [nil, nil, nil],
... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/12_nested_collections/exercises/nested_hash_exercises.rb | Ruby | mit | 308 | main | 2,047 | def find_language_information(languages, language_name)
# Take languages (a nested hash) and language_name as a symbol, return the
# value for the language_name key (which will be another hash!)
# the languages hash will look something like this:
# {
# ruby: { initial_release: 'December 25, 1996', is_beaut... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/12_nested_collections/spec/nested_array_exercises_spec.rb | Ruby | mit | 308 | main | 4,763 | require 'spec_helper'
require_relative '../exercises/nested_array_exercises'
RSpec.describe 'Nested Array Exercises' do
describe 'blank seating chart creation exercise' do
it 'returns a 2d array (chart) containing 2 rows, each containing nil 3 times' do
expected_output = [[nil, nil, nil], [nil, nil, nil]]
... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/12_nested_collections/spec/nested_hash_exercises_spec.rb | Ruby | mit | 308 | main | 7,353 | require 'spec_helper'
require_relative '../exercises/nested_hash_exercises'
RSpec.describe 'Nested hash exercises' do
describe 'find language information exercise' do
let(:hash) do
{
ruby: { initial_release: 'December 25, 1996', is_beautiful?: true },
javascript: { initial_release: 'Decembe... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/1_data_types/exercises/string_exercises.rb | Ruby | mit | 308 | main | 819 | def concatenate_example(string)
# use concatenation to format the result to be "Classic <string>"
"Classic " + string
end
def concatenate(string)
# use concatenation to format the result to be "Hello <string>!"
end
def substrings(word)
# return the first 4 letters from the word using substrings
end
def capit... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/1_data_types/exercises/numbers_exercises.rb | Ruby | mit | 308 | main | 755 | def add(a, b)
# return the result of adding a and b
a + b
end
def subtract(a, b)
# return the result of subtracting b from a
end
def multiply(a, b)
# return the result of multiplying a times b
end
def divide(a, b)
# return the result of dividing a by b
end
def remainder(a, b)
# return the remainder of d... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/1_data_types/spec/numbers_exercises_spec.rb | Ruby | mit | 308 | main | 1,836 | require 'spec_helper'
require_relative '../exercises/numbers_exercises'
RSpec.describe 'Numbers Exercises' do
describe 'addition exercise' do
it 'adds two positive numbers' do
expect(add(1, 2)).to eq(3)
end
it 'adds two negative numbers' do
expect(add(-2, -3)).to eq(-5)
end
end
de... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/1_data_types/spec/strings_exercises_spec.rb | Ruby | mit | 308 | main | 2,607 | require 'spec_helper'
require_relative '../exercises/string_exercises'
RSpec.describe 'String Exercises' do
describe 'concatenation example exercise' do
it 'returns "Classic Ruby"' do
expect(concatenate_example('Ruby')).to eq('Classic Ruby')
end
end
describe 'concatenation exercise' do
it '... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/10_basic_enumerables/exercises/basic_enumerable_exercises.rb | Ruby | mit | 308 | main | 1,045 | def display_current_inventory(inventory_list)
# use #each to iterate through each item of the inventory_list (a hash)
# use puts to output each list item "<key>, quantity: <value>" to console
end
def display_guess_order(guesses)
# use #each_with_index to iterate through each item of the guesses (an array)
# us... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/10_basic_enumerables/spec/basic_enumerable_exercises_spec.rb | Ruby | mit | 308 | main | 3,054 | require 'spec_helper'
require_relative '../exercises/basic_enumerable_exercises'
RSpec.describe 'Basic Enumerable Exercises' do
describe 'display current inventory exercise' do
it 'outputs each inventory item' do
expect($stdout).to receive(:puts).with("apples, quantity: 1")
expect($stdout).to recei... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/8_methods/spec/method_exercises_spec.rb | Ruby | mit | 308 | main | 3,549 | require 'spec_helper'
require_relative '../exercises/method_exercises'
RSpec.describe 'Method Exercises' do
describe 'ASCII translator exercise using #chr' do
it 'returns an uppercase A' do
expect(ascii_translator(65)).to eq('A')
end
# remove the 'x' from the line below to unskip the test
xi... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/8_methods/exercises/method_exercises.rb | Ruby | mit | 308 | main | 1,588 | # Since lesson #8 is on methods, you will be writing the entire method.
# To gain more familiarity, look up the documentation for each hint.
# Remember to unskip the corresponding tests one at a time.
# method name: #ascii_translator
# parameter: number (an integer)
# return value: the number's ASCII character (https:... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/7_hashes/exercises/hash_exercises.rb | Ruby | mit | 308 | main | 1,092 | def create_favorite_hash(color, number)
# return a hash with the following key/value pairs:
# key of color (as a symbol) with value of the color argument
# key of number (as a symbol) with the value of the number argument
end
def favorite_color(favorite_list)
# return the value of the color key
end
def favori... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/7_hashes/spec/hash_exercises_spec.rb | Ruby | mit | 308 | main | 5,228 | require 'spec_helper'
require_relative '../exercises/hash_exercises'
RSpec.describe 'Hash Exercises' do
describe 'create favorite hash exercise' do
it 'returns result with a string and integer' do
favorite = create_favorite_hash('blue', 65)
result = { color: 'blue', number: 65 }
expect(favorit... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/11_predicate_enumerables/exercises/predicate_enumerable_exercises.rb | Ruby | mit | 308 | main | 722 | def coffee_drink?(drink_list)
# use #include? to return true when the drink_list (array) contains the string "coffee" or "espresso"
end
def correct_guess?(guess_list, answer)
# use #any? to return true when any element of the guess_list (array) equals the answer (number)
end
def twenty_first_century_years?(year_l... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/11_predicate_enumerables/spec/predicate_enumerable_exercises_spec.rb | Ruby | mit | 308 | main | 3,262 | require 'spec_helper'
require_relative '../exercises/predicate_enumerable_exercises'
RSpec.describe 'Predicate Enumerable Exercises' do
describe 'coffee drink exercise' do
it 'returns true when coffee is included' do
drink_list = ["coffee", "water", "tea"]
expect(coffee_drink?(drink_list)).to be tr... |
github | TheOdinProject/ruby-exercises | https://github.com/TheOdinProject/ruby-exercises | ruby_basics/9_debugging/spec/debugging_exercises_spec.rb | Ruby | mit | 308 | main | 1,312 | require 'spec_helper'
require_relative '../exercises/debugging_exercises'
RSpec.describe 'Debugging Exercises' do
describe 'decrement_smallest_value' do
# remove the 'x' from the line below to unskip the test
it 'Returns 0 after you use the stack trace to find and fix the error' do
nested_array = [[3,... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.