code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# Methods added to this helper will be available to all templates in the application.
require_dependency 'jsmin'
module ApplicationHelper
include AppFormHelper
#
#=== ローカライズ文字列を返す
#
#指定されたメッセージ区分とメッセージコードに該当する
#ローカライズされた文字列を返す。
#
def app_localized_message(msg_kbn, msg_code)
if @app_messages_has... | Ruby |
# -*- coding: utf-8 -*-
module ProjectHelper
include ApplicationHelper
include AppFormHelper
include ERB::Util
#
#=== プロジェクト名のリンクタグを返す
#
#指定されたプロジェクトオブジェクトから
#該当のプロジェクト名のリンクタグを返す
#
def link_project_name(project, options="")
to = {:controller=>:project, :action=>:index, :id=>project.id}
lin... | Ruby |
module EventHelper
#
#=== ユーザー一覧のプルダウンを返す
#
#イベントに参加可能なユーザーのSELECTタグを出力する。
#
def select_for_eventusers(variable, attribute, options, html_options)
# ユーザー一覧のプルダウンを出力
insobj = instance_variable_get("@#{variable}")
if insobj == nil
select( variable, attribute, {}, options, html_options)
... | Ruby |
module LoginHelper
end
| Ruby |
module AppFormHelper
#
#=== 日付入力フィールドタグ文字列を返す
#
#日付ピックアップダイアログのアイコンを持つ
#日付入力フィールドのタグを出力する。
#
def date_field(object_name, method, options = {})
content_for(:for_ext_scripts) do
opt = {:format => 'Y-m-d'}
apply_ext((object_name.to_s+'_'+method.to_s), 'Ext.form.DateField', opt)
end
... | Ruby |
# -*- coding: utf-8 -*-
module TaskHelper
#
#=== プロジェクト選択プルダウンを返す
#
#参加可能なプロジェクトのSELECTタグを出力する。
#
def select_for_projects(variable, attribute, projectcomp, projects, options, html_options)
if projectcomp.id.nil? || projectcomp.id == ""
# 新規プロジェクト構成データの場合は
# プロジェクト選択プルダウンを出力
collectio... | Ruby |
module Extensions::AirHelper
end
| Ruby |
module AirHelper
end
| Ruby |
module ProjectlogHelper
include ApplicationHelper
include ProjectHelper
include ERB::Util
def disp_projectlog_information(log)
task_key = case log.dat_projectcomp.task_kbn
when 1 then :task#app_localized_message(:label, :task)
when 2 then :milestone#app_localized_message(:lab... | Ruby |
require_dependency 'jsmin'
require 'action_view/helpers/asset_tag_helper'
module JsminHelper
#**
#* javascriptファイルの圧縮とファイル結合スクリプトへパラメータを渡す
#*
def jscomp(paths=null)
if !@jscomp_src
@jscomp_src = Array.new
end
@jscomp_src.push(paths)
end
def csscomp(paths, prefix='')
if !@csscom... | Ruby |
#
#= マイルストーンモデル
#
#
#
class DatMilestone < ActiveRecord::Base
#########################
# 関連定義
#########################
# プロジェクト構成データに所有される(1:1)
belongs_to :dat_projectcomp, :foreign_key => "project_tree_id"
#########################
# 検証機能定義
# (全てのインスタンスで共通の検査項目は、クラスメソッドで定義)
# (:messageの指定は、言語DBのエ... | Ruby |
#
#= プロジェクトユーザモデル
#
#
#
class DatProjectuser < ActiveRecord::Base
#########################
# 関連定義
#########################
# プロジェクトデータに所有される(1:多)
belongs_to :dat_project, :foreign_key => "project_id"
# ユーザーマスタに所有される(1:多)
belongs_to :mst_user, :foreign_key=>"user_id"
# タスクユーザーデータを所有する(1:多)
has_m... | Ruby |
#
#= タスクコメントモデル
#
#
#
class DatTaskcmt < ActiveRecord::Base
#########################
# 関連定義
#########################
# タスクデータに所有される(1:多)
belongs_to :dat_task
end
| Ruby |
#
#= プロジェクトアイテムクラス
#
#
#
class ClsProjectitem
attr_reader :isclass
attr_reader :projectcomp
attr_reader :class_level
#
#=== コンストラクタ
#
#
def initialize( isclass, level, projectcomp )
@isclass = isclass
@projectcomp = projectcomp
@class_level = level
end
#
#=== 分類名を返す
#
#
def n... | Ruby |
#
#= プロジェクトモデル
#WBS,ガントチャート,カレンダーなどプロジェクト構成オブジェクトの一覧を取得する
#また,テンプレートデータ(テンプレートマスタ)から属性値をコピーする
#
class DatProject < ActiveRecord::Base
#########################
# 関連定義
#########################
# プロジェクト構成データを所有する(1:多)
has_many :dat_projectcomps, :foreign_key => "project_id", :dependent=>:destroy
# プロジェクトユーザ... | Ruby |
#
#= テンプレートマイルストーンマスタモデル
#
#
#
class MstTpmilestone < ActiveRecord::Base
#########################
# 関連定義
#########################
# テンプレート構成マスタに所有される(1:1)
belongs_to :mst_composition, :foreign_key => "template_tree_id"
end
| Ruby |
require 'digest/sha1'
#
#= ユーザマスタモデル
#
#ログイン時の認証、パスワードの暗号化・変更を行う。
#
class MstUser < ActiveRecord::Base
attr_accessor :password_confirmation
#
#=== ユーザーオブジェクトを返す
#
#ログインID、パスワードを元にユーザーデータを検索し
#一致した場合(認証OK)はユーザーオブジェクトを返す。
#
def self.authenticate(login, pass)
logger.info login + ':' + pass + ' > ' ... | Ruby |
#
#= プロジェクトコンポーネントモデル
#
#プロジェクト構成オブジェクト(タスク・マイルストーン・イベント)の追加・更新・削除後に
#ログを出力する。
#
#プロジェクト構成オブジェクトの種類はtask_kbnで識別する。
# task_kbn = 1 => タスク
# task_kbn = 2 => マイルストーン
# task_kbn = 3 => イベント
#
class DatProjectcomp < ActiveRecord::Base
#########################
# 関連定義
#########################
# プロジェクトデータに所有される(1:多... | Ruby |
#
#= テンプレートマスタモデル
#
#
#
class MstTemplate < ActiveRecord::Base
#########################
# 関連定義
#########################
# テンプレート構成マスタを所有する(1:多)
has_many :mst_compositions, :foreign_key => "template_id", :dependent=>:destroy
end
| Ruby |
class DatCall < ActiveRecord::Base
end
| Ruby |
#
#= アプリケーションメーラー
#
#サインアップ完了通知・招待・プロジェクト召集のメールを送信する。
#
class AppMailer < Iso2022jpMailer
helper ApplicationHelper
#
#=== サインアップ完了メールを送信する
#
#
def mail_signup_confirm( user, info )
recipients user.email
subject NKF.nkf('-j', info[:subject])
from ActionMailer::Base.smtp_settings[:app_default_f... | Ruby |
# -*- coding: utf-8 -*-
#
#= タスク履歴モデル
#
#
#
class DatTaskhistory < ActiveRecord::Base
#########################
# 関連定義
#########################
# タスクデータに所有される(1:多)
belongs_to :dat_task
belongs_to :update_user, :class_name => 'MstUser', :foreign_key => 'update_user_id'
end
| Ruby |
#
#= テンプレートタスクマスタモデル
#
#
#
class MstTptask < ActiveRecord::Base
#########################
# 関連定義
#########################
# テンプレート構成マスタに所有される(1:1)
belongs_to :mst_composition, :foreign_key => "template_tree_id"
end
| Ruby |
#
#= タスクモデル
#
#
#
class DatTask < ActiveRecord::Base
#########################
# 関連定義
#########################
# プロジェクト構成データに所有される(1:1)
belongs_to :dat_projectcomp, :foreign_key => "project_tree_id"
# タスクコメントデータを所有する(1:多)
has_many :dat_taskcmts, :foreign_key => "task_id", :dependent=>:destroy
# タスクユーザ... | Ruby |
#
#= イベントユーザモデル
#
#
#
class DatEventuser < ActiveRecord::Base
#########################
# 関連定義
#########################
# イベントデータに所有される(1:多)
belongs_to :dat_event, :foreign_key=>"event_id"
# プロジェクトユーザーデータに所有される(1:多)
belongs_to :dat_projectuser, :foreign_key=>"projectuser_id"
end
| Ruby |
class MstMessage < ActiveRecord::Base
end
| Ruby |
#
#= イベントモデル
#
#
#
class DatEvent < ActiveRecord::Base
#########################
# 関連定義
#########################
# プロジェクト構成データに所有される(1:1)
belongs_to :dat_projectcomp, :foreign_key => "project_tree_id"
# イベントユーザーデータを所有する(1:多)
has_many :dat_eventusers, :foreign_key => "event_id", :dependent=>:destroy
# ... | Ruby |
#
#= イベントファイルモデル
#
#
#
class DatEventfile < ActiveRecord::Base
#########################
# 関連定義
#########################
# イベントデータに所有される(1:多)
belongs_to :dat_event
end
| Ruby |
#
#= プロジェクトログモデル
#
#
#
class DatProjectlog < ActiveRecord::Base
#########################
# 関連定義
#########################
# プロジェクト構成データに所有される(1:1)
belongs_to :dat_projectcomp, :foreign_key => "projectcomp_id"
end
| Ruby |
#
#= タスクファイルモデル
#
#
#
class DatTaskfile < ActiveRecord::Base
#########################
# 関連定義
#########################
# タスクデータに所有される(1:多)
belongs_to :dat_task
end
| Ruby |
#
#= テンプレートイベントマスタモデル
#
#
#
class MstTpevent < ActiveRecord::Base
#########################
# 関連定義
#########################
# テンプレート構成マスタに所有される(1:1)
belongs_to :mst_composition, :foreign_key => "template_tree_id"
end
| Ruby |
#
#= テンプレート構成マスタモデル
#
#
#
class MstComposition < ActiveRecord::Base
#########################
# 関連定義
#########################
# テンプレートマスタに所有される(1:多)
belongs_to :mst_template, :foreign_key => "template_id"
# TPタスクマスタを所有する(1:1)
has_one :mst_tptask, :foreign_key => "template_tree_id", :dependent=>:destroy
... | Ruby |
#
#= タスクユーザモデル
#
#
#
class DatTaskuser < ActiveRecord::Base
#########################
# 関連定義
#########################
# タスクデータに所有される(1:多)
belongs_to :dat_task, :foreign_key=>"task_id"
# プロジェクトユーザーデータに所有される(1:多)
belongs_to :dat_projectuser, :foreign_key=>"projectuser_id"
end
| Ruby |
# -*- coding: utf-8 -*-
class UserController < ApplicationController
# 共通レイアウト定義
layout "mainpage"
# フィルタ定義
before_filter :login_required # ログインチェック
before_filter :get_project_info # 更新時もタブ情報の取得は必要
before_filter :user_required # ユーザーチェック
#
#=== アカウント情報編集ページを表示
#
#指定されたユーザのアカウント情報を取得して... | Ruby |
# -*- coding: utf-8 -*-
#
#イベント情報の追加,更新,削除などを行う.
#主にajax経由で呼ばれる.
#
class EventController < ApplicationController
# 共通レイアウト定義
layout "mainpage", :except=>[:block_list, :dlg_index, :dlg_new, :dlg_edit, :dlg_create, :dlg_update, :dlg_destroy]
# フィルタ定義
before_filter :login_required # ログインチェック
# 追加ヘルパー定義
helpe... | Ruby |
# -*- coding: utf-8 -*-
class TaskController < ApplicationController
# 共通レイアウト定義
layout "mainpage", :except=>[:block_list, :block_infolist, :dlg_index, :dlg_new, :dlg_edit, :dlg_create, :dlg_update, :dlg_destroy, :dlg_report]
# フィルタ定義
before_filter :login_required, :except=>[:sync_air] # ログインチェック
# 追加ヘルパー定義... | Ruby |
# -*- coding: utf-8 -*-
class LoginController < ApplicationController
layout 'loginpage' , :except=>[:login, :air_login]
include ApplicationHelper
#
#ログイン画面を表示,及びログイン処理を行う
#
#リクエストメソッドがGETの場合はログイン画面を表示する.
#POSTの場合には,フォームからポストされたuser_login_idとuser_passwordを元にログイン処理を行う
#
#ログインに成功した場合は,プロジェクトのダッシュボードへ... | Ruby |
# -*- coding: utf-8 -*-
class Extensions::AirController < ApplicationController
before_filter :user_authorize, :except => [:login]
@is_logined = false
###########################################################
# メソッド:air_loginアクション
# 概 要:Airアプリからのログイン処理
################################################... | Ruby |
# -*- coding: utf-8 -*-
#
#マイルストーンの追加,編集,削除などを行うコントローラ.
#主にAjax経由で呼ばれる.
#
class MilestoneController < ApplicationController
# 共通レイアウト定義
layout "mainpage", :except=>[:dlg_index, :dlg_new, :dlg_edit, :dlg_create, :dlg_update, :dlg_destroy]
# フィルタ定義
before_filter :login_required # ログインチェック
# 追加ヘルパー定義
helper ... | Ruby |
# -*- coding: utf-8 -*-
class ProjectfileController < ApplicationController
# ヘルパ定義
include ApplicationHelper
###########################################################
# メソッド:dlg_indexアクション
# 概 要:タスク編集ダイアログのためのデフォルトアクション
###########################################################
def dlg_index
end
... | Ruby |
# -*- coding: utf-8 -*-
require 'app_active_record'# ActiveRecord拡張
require_dependency 'login_system'# ログイン機能
#
#アプリケーションコントローラ.
#全てのコントローラの親コントローラとなる.
#
#アプリケーション全体にかかる認証処理やデフォルトで読み込むヘルパの定義を行う
#
class ApplicationController < ActionController::Base
#認証処理を行うライブラリ
include LoginSystem
#--
# フィルタ定義
#++
#ローカライ... | Ruby |
class ProjectuserController < ApplicationController
# フィルタ定義
before_filter :login_required # ログインチェック
#
#=== プロジェクトの参加ユーザを表示する
#
#指定プロジェクトのさんかユーザ一覧を表示する.
#
def block_list
conditions = " dat_projects.valid_flg = 1 "
conditions << " AND dat_projects.id = "
conditions << ((params[:project_id].... | Ruby |
# -*- coding: utf-8 -*-
class ProjectcompController < ApplicationController
# フィルタ定義
before_filter :login_required # ログインチェック
include ProjectItem
#
#=== プロジェクトアイテムの順番の入れ替えを行う
#
#アイテムの行番号を更新する
#
def item_order_update
id = params[:id]
offset = params[:offset]
return unless my_item... | Ruby |
# -*- coding: utf-8 -*-
class ProjectlogController < ApplicationController
# フィルタ定義
before_filter :login_required # ログインチェック
#
#=== プロジェクトの更新履歴を表示する
#
#指定プロジェクトの最新7日間の更新履歴を表示する.
#
def block_list
limit_date = (Date.today - 7).strftime('%Y-%m-%d')
conditions_sql = "dat_projects.valid_flg = 1 AND ... | Ruby |
class LocalizeController < ApplicationController
###########################################################
# メソッド:load_messageアクション
# 概 要:ローカライズ用の言語データを返すアクション(JSON形式)
###########################################################
def load_message
render :text=> "app_messages_hash = " + @app_messages_has... | Ruby |
# -*- coding: utf-8 -*-
#
#= プロジェクトコントローラ
#WBS,ガントチャート,カレンダーなど基本的なデータの表示を行う.
#また,プロジェクトの追加,編集などを行う
#
class ProjectController < ApplicationController
# 共通レイアウト定義
layout "mainpage", :except=>[:block_list, :json_list_for_wbs, :json_list_for_gantt, :json_init_projects, :json_init_project_users, :json_init_project_comps... | Ruby |
ActionController::Routing::Routes.draw do |map|
# The priority is based upon order of creation: first created -> highest priority.
# Sample of regular route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
# Keep in mind you can assign values other than :controller and :action
# ... | Ruby |
# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
module Rails
class << self
def boot!
unless booted?
preinitialize
pick_boot.run
end
end
def booted?
... | Ruby |
# Be sure to restart your web server when you modify this file.
$kcode='u'
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
# ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_G... | Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Full error repor... | Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.ca... | Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between... | Ruby |
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
| Ruby |
require "active_record"
#require 'json'
class ActiveRecord::Base
# before_create :create_user_set
# before_update :update_user_set
#
def to_json(*a)
# result = {"Result" => self.attributes }
#p self.attributes
# result.to_json
self.attributes_before_type_cast.to_json
end
# def create_user_set
# i... | Ruby |
#
# Iso2022Mailer - 日本語メール送信処理プラグイン
#
# from :
# http://wiki.fdiary.net/rails/?ActionMailer (moriq さん)
# http://wota.jp/ac/?date=20050731#p01 (くまくまーさん)
#
# Model で Iso2022jpMailer を継承して使用する
# (see http://d.hatena.ne.jp/drawnboy/20051114/1131977235 )
# TestMailer < Iso2022jpMailer
# ...
# end
#
# MIT License
#
requi... | Ruby |
module ProjectItem
def my_item?(project_comp_id)
user_id = session['user']['id']
item = DatProjectcomp.find(project_comp_id)
logger.debug item.inspect
r = my_project?(item.project_id)
render :text => result_for_json(false, 'Permission Dinied', {}) unless r
r
end
end
| Ruby |
require_dependency "mst_user"
module LoginSystem
protected
# overwrite this if you want to restrict access to only a few actions
# or if you want to check if the user has the correct rights
# example:
#
# # only allow nonbobs
# def authorize?(user)
# user.login != "bob"
# end
def aut... | Ruby |
#
# jsmin.rb 2008-06-08
# Author: UEDA Hiroyuki <BSDmad@gmail.com>
#
# This work is originated from jsmin.rb by Uladzislau Latynski.
# The purpose of translation from jsmin.rb to jsmin.rb ^^;) is
# for using the feature as a class. As a result, you can deploy
# minified JavaScript files with this class as follows:
#
#... | Ruby |
require 'socket'
serv = TCPServer.new(12345)
while sock = serv.accept
i = 0
sock.each_byte {|b|
puts "read: #{b}"
break if (i+=1) == 10000
}
#sock.close
end
| Ruby |
require 'sqlite3'
db = SQLite3::Database.new( "remote.sqllite.db" )
db.execute( "select * from events" ) do |row|
puts row.class
end
db.close
| Ruby |
#!/usr/local/bin/ruby
require 'webrick'
require 'event'
include WEBrick
s = HTTPServer.new(
:Port => 2000,
:DocumentRoot => Dir::pwd
)
$stderr.puts "here"
s.mount_proc("/dump") { |req,res|
$stderr.puts "here"
puts "Class:"+ req.class.to_s
puts "Query:"+ req.query.to_s
puts "query_string:"+r... | Ruby |
require 'base64'
# The server side of the event.
# TODO: session handling, which event from which client,
# user agent.
#
class Event
MOUSE_MOVE = 0x01; # just a standard move event, could be 0x00 if we run out of room ...
MOUSE_DOWN = MOUSE_MOVE << 1 # mouse down event
MOUSE_UP = MOUSE_DOWN << 1 # mo... | Ruby |
class GeometryPacket
attr_accessor :time, :user_agent, :url, :session, :ip
def initialize geom, ip, session=nil
self.time= geom["time"]
self.user_agent= geom["useragent"]
self.ip= ip
if !session && time == 0
initialize_session
elsif !session
return
else
return unless check_session
end
... | Ruby |
#!/usr/bin/env ruby
require 'simple_http'
require 'digest/sha1'
require 'constants'
module Bulkupload
module Protocol
# Logs on to the server and retrieves a session
class Login
# Parameters
# user
# password
# host_uri
#
# raises exception if login fails or no session is retu... | Ruby |
require 'DB'
require 'persistence/persistence'
module Bulkupload
module Persistence
module Mysql
########################################################################
# Mysql housekeeping.
########################################################################
def self.set_db instance, user, passwd
@dr... | Ruby |
module Bulkupload
module Persistence
module SQLite
class SqliteSession < SessionBase
def initialize user=nil, password=nil, client_ip=nil
super
if user && password && client_ip
# Request to create a new Session.
init
end
end
def touch
"UPDATE bulk_session SET last_seen = date('now') WHERE... | Ruby |
require 'digest/sha1'
module Bulkupload
module Persistence
PASSWD_SALT_SECRET = "secret" #TODO externalize
class SessionBase
attr_accessor :session_id, :session_token, :user_name, :user_id
def initialize user=nil, password=nil, client_ip=nil
# check user password || exception
# init session id... | Ruby |
module Bulkupload
module Protocol
# HTTP Header fields
X_BULK_FUNCTION = 'x-bulk-function'
X_BULK_USER = 'x-bulk-user'
X_BULK_PASSWORD = 'x-bulk-password'
X_BULK_STATUS = 'x-bulk-status'
X_BULK_SESSION = 'x-bulk-session'
X_BULK_FILENAME = 'x-bulk-filename'
X_BULK_LENGTH = 'x-bulk-length'
X_BULK_CHUN... | Ruby |
#!/usr/bin/env ruby
require 'simple_http'
require 'digest/sha1'
require 'constants'
module Bulkupload
module Protocol
# Logs on to the server and retrieves a session
class Login
# Parameters
# user
# password
# host_uri
#
# raises exception if login fails or no session is retu... | Ruby |
class FileDigest
def self.sha1 filename
sha1 = Digest::SHA1.new()
File.open(filename) { |file|
bytes = nil
while (bytes = f.read(1024))
sha1.update(bytes)
end
}
sha1.digest
end
def self.check filename, sha1
return sha1(filename) == sha1
end
end
module Bulkupload
module Protocol
cl... | Ruby |
class ClieOp03
attr_accessor :fileheader, :batches, :items
end # CliepOp03
class ClieOpRecord
def initialize
self.class.addMethods
end
# CliepRecords are composed of a number of fields that are defined as follows:
# [name, :alpha|:numeric, length, describtion, content?]
# Definition contains an array of... | Ruby |
require "rake/rdoctask"
require "rake/gempackagetask"
require "rake/testtask"
require "rake/clean"
require "rubygems"
# Some definitions that you'll need to edit in case you reuse this
# Rakefile for your own project.
SHORTNAME ='hexy' # this should be the rubyforge project name
DESC ='Utility for hexdumps'
PKG_VERS... | Ruby |
class Hexy
def self.dump bytes, config={}
Hexy.new(bytes, config).to_s
end
#
# Constructor is passed the bytes to format as a hex dump and
# an optinal configuration hash. Configuration parameters are:
#
# [:+width+] how many bytes per line (default: 16)
# [:+numbering+] currently the ... | Ruby |
require 'test/unit'
require File.dirname(__FILE__) + '/../lib/hexy'
# The way these tests are grouped is more or less arbitary, it more or less follows
# the features available in the config hash and tries to cover several permutations.
# The tests in the current form are taken from runs of the actual code:
# they're... | Ruby |
require "rake/rdoctask"
require "rake/gempackagetask"
require "rake/testtask"
require "rake/clean"
require "rubygems"
# Some definitions that you'll need to edit in case you reuse this
# Rakefile for your own project.
SHORTNAME ='aio' # this should be the rubyforge project name
DESC ='Utility for aio'
PKG_VERSION =... | Ruby |
class Line
# options are:
# :textwidth default 72
# :prefix default ""
# :nl default "\n"
def Line.break line, options={}
nl = options[:nl] || "\n"
r = Regexp.new(nl)
line.gsub!(r,"")
_break line, "", options
end
def Line._break line, collect, options
textwidth =... | Ruby |
require "rake/rdoctask"
require "rake/gempackagetask"
require "rake/testtask"
require "rake/clean"
require "rubygems"
# Some definitions that you'll need to edit in case you reuse this
# Rakefile for your own project.
SHORTNAME ='bytes' # this should be the rubyforge project name
DESC ='Routines to manipulate bytes'... | Ruby |
require "bytes.rb"
module Bytes
#
# The `byte_accessor` method becomes available to your class by
# including the `Bytes` module. The method is used for meta-programming,
# it takes a symbol, which becomes the name of an instance variable and
# accessors to store and access the byte value. The second par... | Ruby |
module Bytes
# Utility method to converts a ruby numeric (255- -128) to it's
# hex representation.
def self.hex b
raise "value too large #{b}" if b > 255 || b < -128
"%02x" % b
end
# Utility method to converts a ruby numeric (255- -128) to it's
# octal string representation.
def self.octal b
... | Ruby |
require 'test/unit'
require File.dirname(__FILE__) + '/../lib/bytes_ng.rb'
class Something
include Bytes
byte_accessor :something, "1... ...." => :bit8_s,
".1.. ...." => :bit7_s,
"..vv vv.." => :value_s
byte_accessor :the_other, "1... ...." => :bit8_o,
... | Ruby |
require 'test/unit'
require File.dirname(__FILE__) + '/../lib/bytes.rb'
class TestByte < Test::Unit::TestCase
def setup
end
def test_8_bits
b = Bytes::Byte.new "1... ...." => :bit8,
".1.. ...." => :bit7,
"..1. ...." => :bit6,
... | Ruby |
#!/usr/bin/env ruby
# File: script/console
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
libs = " -r irb/completion"
libs << " -r #{File.dirname(__FILE__) + '/../lib/bytes.rb'}"
puts "Loading bytes gem"
exec "#{irb} #{libs} --simple-prompt"
| Ruby |
#!/usr/bin/env ruby
# File: script/console
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
libs = " -r irb/completion"
libs << " -r #{File.dirname(__FILE__) + '/../lib/bytes.rb'}"
puts "Loading bytes gem"
exec "#{irb} #{libs} --simple-prompt"
| Ruby |
require "rake/rdoctask"
require "rake/gempackagetask"
require "rake/testtask"
require "rake/clean"
require "rubygems"
# Some definitions that you'll need to edit in case you reuse this
# Rakefile for your own project.
SHORTNAME ='tlv' # this should be the rubyforge project name
DESC ='lib for handling tlv data'
PKG_... | Ruby |
class TLV
class Field
attr_accessor :display_name, :name, :length
def initialize clazz, desc, name=nil, len=0
@length=len
unless name
name = desc.gsub(/\s/, "_")
name = name.gsub(/\W/, "")
name = name.downcase.to_sym
end
@name = name
@display_name = desc
define_accessor cla... | Ruby |
class TLV
def get_bytes
if self.class.primitive? || (self.is_a?(DGI) && fields.length!=0) || self.class.is_raw?
bytes = get_bytes_primitive
else
bytes = get_bytes_constructed
end
end
def get_bytes_primitive
bytes = ""
fields.each { |field|
bytes << self.send(field.n... | Ruby |
class TLV
class B < Field
def define_accessor clazz
super
name = @name
len = @length
clazz.instance_eval{
define_method("#{name}="){|val|
raise("invalid value nil") unless val
raise("must be a String #{val}") unless val.is_a?(String)
raise("... | Ruby |
class TLV
class << self
CLASS_MASK = 0xC0
UNIVERSAL_CLASS = 0x00
APPLICATION = 0x40
CTX_SPECIFIC = 0x80
PRIVATE = 0xC0
BYTE6 = 0x20
def universal?
((@tag & CLASS_MASK) == UNIVERSAL_CLASS) if @tag
end
def application?
((@tag & CLASS_MASK) == APPLICATION) if ... | Ruby |
class TLV
# def self.register tag, clazz
# @tlv_classes ||= {}
# @tlv_classes[tag] = clazz
# end
def self.b2s bytestr
r = bytestr.unpack("H*")[0]
r.length > 1 ? r : " "
end
def self.s2b string
string = string.gsub(/\s+/, "")
string = "0" + string unless (string.length % 2 == 0)
[... | Ruby |
class TLV
class << self
def mand_tags
@mand_tags ||= (self == TLV ? [] : superclass.mand_tags.dup)
end
def opt_tags
@opt_tags ||= (self == TLV ? [] : superclass.opt_tags.dup)
end
# Takes either a subclass of TLV or the following options, which are used to
# create an su... | Ruby |
class TLV
# return [tlv, rest], the parsed TLV and any leftover bytes.
def self.parse bytes
tlv, _ = self._parse bytes
return tlv
end
def self._parse bytes
return nil unless bytes && bytes.length>0
tag, _ = self.get_tag bytes
impl = lookup(tag)
tlv = impl.new
rest = tlv.parse(bytes... | Ruby |
class DGI < TLV
def self.get_length(bytes)
len = bytes[0] #CPS 2.2 Creation of ...
if len == 0xFF
len = bytes[1,2].unpack("n")[0]
end
num = len > 0xfe ? 3 : 1
rest = bytes [num, bytes.length]
[len, rest]
end
def self.check_tag
raise "incorrect tag length, dgi must be 2 : #{... | Ruby |
class TLV
class Raw < Field
def initialize clazz, desc=nil, name=nil, len=0
desc ||= "Value"
super
end
def define_accessor clazz
super
name = @name
clazz.instance_eval{
define_method("#{name}="){|val|
val ||= ""
raise("must be a String #{val}") u... | Ruby |
require 'tlv/field'
require 'tlv/tlv'
require 'tlv/b'
require 'tlv/raw'
require 'tlv/parse'
require 'tlv/tag'
require 'tlv/constructed'
require 'tlv/to_bytes'
require 'tlv/dgi'
| Ruby |
require "rake/rdoctask"
require "rake/gempackagetask"
require "rake/testtask"
require "rake/clean"
require "rubygems"
# Some definitions that you'll need to edit in case you reuse this
# Rakefile for your own project.
SHORTNAME ='aio' # this should be the rubyforge project name
DESC ='Utility for aio'
PKG_VERSION =... | Ruby |
require "rake/rdoctask"
require "rake/gempackagetask"
require "rake/testtask"
require "rake/clean"
require "rubygems"
# Some definitions that you'll need to edit in case you reuse this
# Rakefile for your own project.
SHORTNAME ='snippets' # this should be the rubyforge project name
DESC ='Random stuff I use'
PKG_VE... | Ruby |
module Bytes
def in_range byte, from, to
byte >= from && byte <= to
end
end
| Ruby |
def check_valid_file file_or_file_name, extension=:ignore
raise "#{file_or_file_name} is not a file or a file name" unless (file_or_file_name.is_a?(File) || file_or_file_name.is_a?(String))
file = nil
if file_or_file_name.is_a? String
raise "#{file_or_file_name} is not readable" unless File.readable? file_... | Ruby |
module Bytes
def Bytes.check_byte b
raise "not in byte range: #{b}" unless (b.is_a?(Numeric) && b>-1 && b<256)
end
def Bytes.check_bytes arr
arr.each {|val|
check_byte val
}
end
def Bytes.bytestr2numeric bs
bs.unpack("C")[0]
end
def Bytes.numeric2bytestr num
[num].pack("C")
end
def Bytes.sample from... | Ruby |
require "rake/rdoctask"
require "rake/gempackagetask"
require "rake/testtask"
require "rake/clean"
require "rubygems"
# Some definitions that you'll need to edit in case you reuse this
# Rakefile for your own project.
SHORTNAME ='Bytes' # this should be the rubyforge project name
DESC ='Ruby byte handling'
PKG_VERSI... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.