Class: UserHouse

Inherits:
DataHouse show all
Defined in:
lib/common/data_house.rb

Overview

用户库

Example

require ‘data_house’

Constant Summary collapse

@@instance =
nil

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DataHouse

#initialize, #size

Constructor Details

This class inherits a constructor from DataHouse

Class Method Details

.get_instanceObject



54
55
56
57
# File 'lib/common/data_house.rb', line 54

def self.get_instance
	@@instance = new("user") unless @@instance
	@@instance
end

Instance Method Details

#get_a_nobodyObject

随机取得一个用户



60
61
62
# File 'lib/common/data_house.rb', line 60

def get_a_nobody
	@data_house.at rand(@data_house.size)
end

#get_by_name(name) ⇒ Object

根据用户名取用户

Example:

user = UserHouse.get_instance.by_name “ruguo” puts user



70
71
72
73
74
# File 'lib/common/data_house.rb', line 70

def get_by_name(name)
	@data_house.find do |u|
		u["name"] == name if u.key? "name"
	end
end

#get_by_tag(tag) ⇒ Object

根据Tag来取用户,user.house中的多个tag可以用空格来分隔

Example:

user = @user_house.by_tag “haha”

# @user_house在SystemTest的setup中经过初始化 # @user_house = UserHouse.get_instance

puts user

# user.house的内容如下#— #- name: ruguo # password: aaaa # spaceurl: ruguo32 # tag : haha hoho gaga



93
94
95
96
97
# File 'lib/common/data_house.rb', line 93

def get_by_tag(tag)
	@data_house.find do |u|
		u["tag"].split(/\s+/).include?(tag) if u.key? "tag"
	end
end