.


:




:

































 

 

 

 


Ruby




- , mechanize sinatra.

Mechanize , , . () css xpath [7].

Sinatra Ruby, -. Ruby Ruby on Rails Merb [8].

. Sinatra , , , Model-View-Controller (--), -, Ruby on Rails. Sinatra - [8].

 

 

-, . - , . () .

.

-

- http .

ruby- Sinatra.

.

# coding: utf-8

require 'mechanize' // mechanize

require 'sinatra' // sinatra

require './my' // my

require 'json' // json json

enable:static //

set:server, 'webrick' // , http

get '/' do // (localhost:8080/)

haml:index // haml index.haml

end

 

get '/find' do // localhost:8080/find

@param=params[:q]

@f=func(@param,params[:y1],'2013')

 

haml:find

end

Ruby (if,def,for ) . , :

def doSomething(a,b)

if(a>b)

return True

else

return False

end

end

/ - index.haml, haml-, html- .

Haml Sass , Ruby . , html , haml .

:

/

views

find.haml

index.haml

footer.haml

form.haml

public

style.sass

script.coffee

style.css

index.haml. . index.haml

%html

%head

%link{rel:'stylesheet',href:'style.css'}

 

%body

%center

.container

.header

=haml:form

%, Ruby =. -:

container.

( form.haml)

:

 

%form{method:'GET',action:'find'}

%table.form

%tr

%td.right

%label{for:'q'} :

%td

%input.q{type:'text',name:'q'}

%tr{align:'right'}

%td.right

%label{for:'y',align:'right'} :

%td

%select.y{name:'y1'}

%option 2000

%option 2001

%option 2002

%option 2003

%option 2004

%option 2005

%option 2006

%option 2007

%option 2008

%option 2009

%option 2010

%option 2011

%option 2012

%option 2013

%option 2014

%option 2015

%option 2016

%option 2017

%option 2018

%option 2019

%option 2020

%option 2021

%option 2022

%tr{align:'center'}

%td.center{colspan:'2'}

%br

%input.submit{type:'submit',value:''}

.center center - , #id - id. . index.haml style.css, style.sass:

@mixin border-radius($radius: 1px) //

-webkit-border-radius: $radius

-moz-border-radius: $radius

border-radius: $radius

.main

width: 1000px

height: auto

background-color: black

#item

width: 100%

height: auto

text-align: left

@include border-radius(5px)

background-color: lighten(#545657,20)

margin-top: 5px

margin-down: 5px

 

.container

width: 1000px

height: auto

body

background-color: white

margin: 0px

td.left

text-align: left

td.right

text-align: right

td.center

text-align: center

 

select

width: 100%

input.submit

width: 300px

 

table.form

width: 400px

 

input.q

width: 100%

 

.header

width: 100%

height: 100px

background-color: grey

style.sass, style.css.

, , find.haml,

%html

%head

%link{rel:'stylesheet',href:'style.css'}

%script{src:'script.js'}

%body

%center

=haml:form

.main

%center

-for i in @f do

#item

%strong :

%br

="   &nbsp"+i[0].to_s

%p

%strong :

%br

="   &nbsp"+i[1].to_s

Haml' , .

-for i in @f do , @f. -. Haml Sass . , Ruby, init.rb my.rb. init.rb , my.rb.

 

# coding: utf-8

require 'mechanize'

def mark(m,n)

i=n*m/(n+30)

j=7.2453*n/(n+30)

return i+j

end

def func(q,y1,y2)

m=Mechanize.new

link="http://window.edu.ru/catalog/resources?p_str=#{q}&p_year1=#{y1}&p_year2=#{y2}&p_sort=5&p_frubr=3.52.5"

link=link+"&p_page=1"

page=m.get link

links=[]

links<<link

page.search('table.pager').search('td').search('a').each do |i|

links<<'http://window.edu.ru'+i['href']

end

u=[]

links.each do |l|

o=m.get l

n=0

o.search('div.res_l').search("a.restitle").each do |i|

 

href='http://window.edu.ru'+i['href']

k='http://open.dapper.net/transform.php?dappName=diploma&transformer=HTML&extraArg_microFormat=1&applyToUrl='+href

j=m.get k

mark=j.search('span.mark')

mark=mark.text.to_f

biblio=j.search('span.biblio').text

num=j.search('span.num')

num=num.text.to_f

ma=mark(mark,num)

if ma>1

dl=''

if j.search('span.link')

dl=j.search('span.link').search('a')[0]['href']

u<<[biblio,ma,dl]

 

end

end

if u.size>=5

return u

end

 

end

end

return u

 

end

. http://open.dapper.net. .

 


 

-

, http .

ruby init.rb. :

 

 

. pid=3853. Http- -

4567.

localhost:4567 index.haml

.

2000 .

, find.haml

 

 

 

2000

 

frame-col-ypos:0,141667in; bot-style:none; xpos:0,000694in; wrap-mode:wrapped-both; frame-type:image; ypos:0,141667in; top-style:none; frame-height:0,968056in; frame-pref-page:24; left-style:none; position-to:block-above-text; frame-col-xpos:0,000694in; right-style:none; frame-width:6,691667in


 

-, . Ruby . Ruby , . , Haml,Sass CoffeeScript. . . . . . .

 

:

1.

2. (Ruby,Haml,Sass,CoffeeScript)

3. WWW

4.


 

 

 

1. . URL: http://ru.wikipedia.org/wiki/_

2. . URL: http://www.shipbottle.ru/projects/txt/internet_2_1998/index.shtml

4. Ruby/ Ruby. URL: http://ru.wikibooks.org/wiki/Ruby/__Ruby

5. Haml. URL: http://ru.wikipedia.org/wiki/Haml

6. Sass. URL: http://ru.wikipedia.org/wiki/Sass

7. Ruby. URL: http://leonid.shevtsov.me/ru/druzya-druzej-vkontakte-na-ruby

8. Sinatra. URL: http://ru.wikipedia.org/wiki/Sinatra

 


 

 


 





:


: 2015-11-05; !; : 436 |


:

:

- , - .
==> ...

781 - | 754 -


© 2015-2024 lektsii.org - -

: 0.058 .